Can I combine position: relative and float: left?

前端 未结 5 1602
逝去的感伤
逝去的感伤 2021-02-01 14:40

Can I apply both position: relative and float: left on one element? Like this:

div {
  float: left;
  position: relative;
  top: 0px;
          


        
5条回答
  •  隐瞒了意图╮
    2021-02-01 15:33

    I want to provide a different answer in case it may help someone. I had two side by side div's that I wanted them to take up space:

    stuff
    other stuff

    I used to do this by applying

    after all my floating ones. This used to work because .clear { clear: both; } would solve the problem. This no longer works for me. Instead, I followed these instructions and added this class to my container:

    .noFloat {
        width: 100%;
        overflow: auto; //If you get a scroll bar, try overflow: hidden;
        float: none;
    }
    

    so I ended up with:

    ...

    Here is a link to a bootply.com example: http://www.bootply.com/EupCHRhV4s

提交回复
热议问题