Skip to content

Files

Latest commit

e731616 · Apr 8, 2018

History

History
27 lines (19 loc) · 938 Bytes

css-wi-he-code.md

File metadata and controls

27 lines (19 loc) · 938 Bytes

span标签的width和height分别为多少?

<div style=”width:400px;height:200px;”>
  <span style=”float:left;width:auto;height:100%;”>
    <i style=”position:absolute;float:left;width:100px;height:50px;”>hello</i>
  </span>
</div>

问题:span标签的width和height分别为多少?

  • A. width = 0px,height = 0px
  • B. width = 400px,height = 200px
  • C. width = 100px,height = 50px
  • D. width = 0px,height = 200px

?> 答案: D

解析:

span元素因为float之后会变成行内块级元素(默认宽度是auto),因此height:100% 也就是父级元素的200px

i元素因为absolute之后会脱离文档流, 因而不占用正常的文档流,span下面没有其他元素,width就是0, 这也就是塌陷现象

参考资料:

题目来源