小编Ken*_*ard的帖子

为什么内联元素在浮动时表现得像块级元素?

在CSS规范中它定义了这种行为?

正如这两篇文章所述......

粉碎杂志

当您浮动元素时,它将变为块框

CSS技巧

浮动的元素是自动的 display: block;


示例: https ://jsfiddle.net/kennethcss/y6cmgubt/

a {
  /* for looks */
  background-color: #e1e1e1;
  line-height: 30px;
  text-align: center;

  /* Comment "float: left" out to test. Once the float is removed, neither
   * the height or width have any effect on the anchor because its default
   * display is inline.
   */
  height: 30px;
  float: left;
  width: 100px;
}
Run Code Online (Sandbox Code Playgroud)
<nav>
  <a>Nav Item 1</a>
  <a>Nav Item 2</a>
  <a>Nav Item 3</a>
</nav>
Run Code Online (Sandbox Code Playgroud)

css css-float language-lawyer

5
推荐指数
1
解决办法
625
查看次数

标签 统计

css ×1

css-float ×1

language-lawyer ×1