简体   繁体   English

Bootstrap 4 sticky-top margin-top

[英]Bootstrap 4 sticky-top margin-top

I have element sidebar and div with class sticky-top :我有元素侧边栏和 div 类sticky-top

<div class="row">
   <div class="col-lg-4">
      <div class="sticky-top">
           ....
      </div>
   </div>
</div>

I need pass a margin, when sidebar is sticky, because class sticky-top doesn't have a margin-top.当侧边栏是粘性的时,我需要传递一个边距,因为粘性顶部类没有边距顶部。

How I can write margin when sidebar is sticky?当侧边栏有粘性时如何写边距?

尝试:

.sticky-top { top: 0.5em; }

You need to use top instead of margin-top您需要使用top而不是margin-top

<div class="row">
    <div class="col-lg-4">
        <div class="sticky-top" style="top: 30px">
            ....
        </div>
    </div>
</div>

Try to use:尝试使用:

.sticky-top{
  margin-top:10px;
}

if it gives you trouble, you can force it with !important , like this:如果它给您带来麻烦,您可以使用!important强制它,如下所示:

.sticky-top{
  margin-top:10px !important;
}

Please note that !important should be used only when other solutions are not working.请注意,仅当其他解决方案不起作用时才应使用 !important。

Hope it help!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM