How to make the float left and float right on the same line?

后端 未结 5 2356
长发绾君心
长发绾君心 2021-02-20 09:26

The Problem:

     **The left part** (#nav ul li) which float: left
     and **the right part** (#nav .search) which float: right
            **are n         


        
5条回答
  •  遥遥无期
    2021-02-20 09:48

    An alternative to the solutions already mentioned is to flip the order of the markup around, so that the right-floating item comes first.

    #nav ul li {
      float: left;
      list-style: none;
      margin: 0 20px;
    }
    #nav .search {
      float: right;
    }

    You don't have to do anything else. No other CSS or markup is needed.

提交回复
热议问题