CSS to achieve a similar fixed floating div thast always on top of other divs - like stackoverflow does?

前端 未结 2 2124
慢半拍i
慢半拍i 2021-02-10 08:00

I\'d like to achieve a similar effect as the one in this image:

Basically, I want to have a div as a menu bar that\'s always on top - the div beneath it being

相关标签:
2条回答
  • 2021-02-10 08:34

    You need to use the position: fixed; property for #top div.

    <div id="top"></div>
    
    #top {
      position:fixed;
      top:0px;
      width:100%;
      height:70px;
    }
    
    0 讨论(0)
  • 2021-02-10 08:36

    You need to have a div and assign the CSS classes:

    .className {
    width: 100%;
    position: fixed;
    top: 0px;
    height: 75px;
    }
    

    Then on your div have: <div class="className">Whatever</div>

    0 讨论(0)
提交回复
热议问题