【发布时间】:2011-11-01 09:51:44
【问题描述】:
CSS Float 让我抓狂了,谁能解释一下下面的情况?
如何重现:只需复制以下代码sn-p from
http://www.w3schools.com/css/tryit.asp?filename=trycss_float_clear
为什么没有clear:both 不起作用?
<html>
<head>
<style type="text/css">
.thumbnail
{
float:left;
width:110px;
height:90px;
margin:5px;
}
.text_line
{
display:block;
height:90px;
width:300px;
margin:0px;
background-color:red;
}
</style>
</head>
<body style="display:block">
<h3>Image Gallery</h3>
<p>Try resizing the window to see what happens when the images does not have enough room.</p>
<img class="thumbnail" src="klematis_small.jpg" width="107" height="90">
<img class="thumbnail" src="klematis2_small.jpg" width="107" height="80">
<img class="thumbnail" src="klematis3_small.jpg" width="116" height="90">
<img class="thumbnail" src="klematis4_small.jpg" width="120" height="90">
<p class="text_line">a</p>
<img class="thumbnail" src="klematis_small.jpg" width="107" height="90">
<img class="thumbnail" src="klematis2_small.jpg" width="107" height="80">
<img class="thumbnail" src="klematis3_small.jpg" width="116" height="90">
<img class="thumbnail" src="klematis4_small.jpg" width="120" height="90">
</body>
</html>
【问题讨论】:
-
似乎按预期工作。你能解释一下问题是什么,以及你想要达到的具体目标吗?
-
对我来说,你拿走了一些东西(
clear: both;)似乎真的很奇怪,然后你想知道它是如何不像 w3school 示例那样工作的。如果您删除或替换某些东西并且停止工作..您可能希望将其放回原处。 -
作为记录,w3schools is bad,如果您想了解浮点数,floatutorial 可能是更好的资源。
-
我试图了解“视觉格式化模型”的机制。 w3.org/TR/CSS2/visuren.html