Home  >  Article  >  Web Front-end  >  “Inline-block” 和 “float” 分别在什么时候用?_html/css_WEB-ITnose

“Inline-block” 和 “float” 分别在什么时候用?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:41:281235browse

Inline-block 和 float 分别在什么时候用???

有时候“Inline-block” 和 “float” 都能实现横向排列的效果,二者分别在什么时候用???

分别适合于什么情况???




回复讨论(解决方案)

这样的问题 
其实你应该先说 这2个的实现效果是什么 步能因为部分重叠的功能 影响你的应用

“float” 主要用来进行列布局的;

行内元素(内联元素)是不能设置width、padding-left、padding-right等属性的,
如果你需要设置这些属性时,同时又不想它独占一行空间,就需要设置这个内联“display: inline-block”;

“inline-block”用得不是很多,大多数情况下“block”是可以替代“inline-block”的。

“行内元素(内联元素)是不能设置width、padding-left、padding-right等属性的” 这句话错了,
除了“Inline-block” 和 “float” 分别在什么时候用?_html/css_WEB-ITnose,内联元素不能设置width、height、padding-top、padding-bottom、margin-top、margin-bottom。

楼上解释的都很不错!总的说来就是需要让元素同时具备行间元素的特性,同时也具体控制宽高的地方使用。兼容性有问题,float是脱离文档流进行排版使用!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn