javascript - inline and inline-block difference in "responsive web design with html5 and css3" -
i came across question when reading "responsive web design html5 , css3" chapter3 fluid layouts. author trying change fixed pixel size percent-based fluid size. below html , css code.
html:
<div id="wrapper"> <div id="navigation"> <ul> <li><a href="#">something</a></li> <li><a href="#">some other thing</a></li> </ul> </div> css:
#navigation ul li{display:inline-block;} #navigation ul li {margin-right:25px;} given outermost #wrapper of 940px width. author showed naively change margin-right 25px 2.66%(25/940) doesn't work because intermediate parent of <a> <li>, wasn't given specific width.
besides author's suggested solution, author provided solution, change "display:inline-block" "display:inline".
while can understand difference between inline , inline-block extent, these 2 stackoverflow passages(1,2), don't know how works in case.
i guess inline stuff cannot stick close each other, inline-block can. right?
i'm grateful advice. thanks!
the definition percentage margins says
the percentage calculated respect width of generated box's containing block.
the generated box of a element, , containing block nearest block container ancestor.
elements inline-block block containers, when li element inline-block, a element's containing block, , margin percentage of width of li element.
furthermore, shrink-to-fit nature of inline-block elements, creates circular dependency. margin depends on width of li element, , width of li element depends on margin of a element. in such cases, normal margins adjusted resolve such situations, in case setting them 0.
elements inline not block containers, when li element inline, ul element a element's containing block, , margin percentage of width of ul element, same width of #wrapper element.
Comments
Post a Comment