html - float 元素的 width auto 和 width 100% 之间的区别

标签 html css

difference between width auto and width 100 percent的答案中所述宽度 auto 占满宽度,但在这个 demo 中width auto 不占用全宽,但是当我们对其应用 100% 时,它只占用全宽。 width auto 实际上是如何取其元素的?

演示总结

html

<ul>
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>

CSS

ul{background-color: gray;}
li{background-color: red; float: left; clear: left; width: auto;}

最佳答案

问题是 li 元素上的 float 。

如果你像这样从你的 css 中删除 float 部分:

ul{background-color: gray;}
li{background-color: red; width: auto;}

然后它工作正常。

关于html - float 元素的 width auto 和 width 100% 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17484215/

相关文章:

html - 跨度换行问题

javascript - 如何将变量从 php 插入到 p 标签(html)中?

css - 内容属性文本颜色 - css

javascript - 使用 Jquery 通过鼠标单击进行单选,通过 CTRL + 单击 div 内的图像进行多选

html - Bootstrap 出于某种原因在 <td> 中垂直移动 <strong> 文本——如何解决这个问题?

python - 更改单选按钮,然后使用 mechanize (python) 读取()

html - 事件中无效的 Schema.org 位置属性

php - 将图像链接到标签并使用复选框选择哪些标签

javascript - 从子页面导航到主页面并滚动到id的方法

javascript - 将文本字段元素添加到 div 的样式