How to display inline several
  • with 100% width?
  • 后端 未结 7 1377
    灰色年华
    灰色年华 2020-12-21 01:24

    I have the following html:

    • element 1
    • element 2
    <
    7条回答
    •  执念已碎
      2020-12-21 01:47

      Like the others I'm struggling to understand what you're looking for exactly but does this do what you want?

      
      
      
          Horizontal 100% LIs
          
      
      
          
      • element 1
      • element 2
      • element 3

      Getting the LIs on to one line has two parts. The white-space:nowrap on the ul stops any automatic wrapping and the display:inline-block on the LIs allows them to run one after another, but have widths, paddings and margins set on them. For standards compliant browsers that's sufficient.

      However IE6 and IE7 need special treatment. They don't support the display:inline-block properly, but fortunately display:inline on elements with hasLayout set gives a behaviour very like display:inline-block. The width:100% has already forced hasLayout to be set on the LIs so all we have to do is to direct the display:inline to IE6 and IE7 only. There are a number of ways of doing this (conditional comments are popular on StackOverflow) but here I've chosen the * html and *:first-child+html hacks to do the job.

      Additionally, IE6 and IE7 have another bug where the scroll bar overlays the content, so the container is given a padding-bottom to make space for the scroll bar. The scroll bar is a platform control, so its height cannot be known exactly, but 17 pixels seems to work for most cases.

      Finally, IE7 also wants to put in a vertical scroll bar, so the overflow-y:hidden directed at IE7 stops this from happening.

      (The padding:0, margin:0, list-style:none, and the styles on the individual LIs are just there to show more clearly what's happening.)

    提交回复
    热议问题