How can I prevent floated div elements from wrapping when the browser is re-sized?

前端 未结 5 1540
眼角桃花
眼角桃花 2020-12-24 11:16

How do you make DIV\'s that are floated left next to each other not wrap when the browser is re-sized such that the viewport becomes smaller?

div {
  float:          


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 11:49

    I'm pretty late to the game, but here's what I've found that works:

    Let's say you have a navigation structured as:

    
    

    To get it to display the links inline, without ever wrapping, you can simply use:

    nav ul {
        white-space: nowrap;
    }
    
    nav ul li {
        display: table-cell;
    }
    

    No fixed widths or anything required.

    Fiddle: http://jsfiddle.net/gdf3prb4/

提交回复
热议问题