Of the options you asked about:
float:left;
I dislike floats because of the need to have additional markup to clear the float. As far as I'm concerned, the whole float
concept was poorly designed in the CSS specs. Nothing we can do about that now though. But the important thing is it does work, and it works in all browsers (even IE6/7), so use it if you like it.
如果使用:after
Select 器清除浮动,则可能不需要额外的清除标记,但如果希望支持IE6或IE7,则这不是一个选项.
display:inline;
This shouldn't be used for layout, with the exception of IE6/7, where display:inline; zoom:1
is a fall-back hack for the broken support for inline-block
.
display:inline-block;
This is my favourite option. It works well and consistently across all browsers, with a caveat for IE6/7, which support it for some elements. But see above for the hacky solution to work around this.
inline-block
的另一个大警告是,由于内联方面的原因,元素之间的空白被视为与文本单词之间的空白相同,因此可以在元素之间出现空白.这方面有很多解决办法,但没有一个是理想的.(最好是元素之间不要有任何空格)
display:table-cell;
Another one where you'll have problems with browser compatibility. Older IEs won't work with this at all. But even for other browsers, it's worth noting that table-cell
is designed to be used in a context of being inside elements that are styled as table
and table-row
; using table-cell
in isolation is not the intended way to do it, so you may experience different browsers treating it differently.
Other techniques you may have missed? Yes.
希望有帮助.