样式无序列表中出现奇怪的换行符?
我遇到了一个非常奇怪的具体问题,我将尝试将代码粘贴到此处,而不会使问题过于混乱。我有一个无序列表,它使用样式表将每个列表项放入一个小方块中......但在某个点之后,换行符有点疯狂。如果你添加或删除不同的,换行符就会移动,我一辈子都无法弄清楚发生了什么。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<link rel="stylesheet" type="text/css" href="primaryStyle.css" />
</head>
<body>
<center>
<table class="table" border="0" width="750">
<tr>
<td>
<div id="productresults">
<ul class="productlist" >
<li class="productresultli"><center>
<span id="Span3">Seasonal Fruit Tray</span><br />
<span id="Span4">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span5">Seasonal Fruit Tray</span><br />
<span id="Span6">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span17">Seasonal Fruit Tray</span><br />
<span id="Span18">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_12">Mayonaise</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_12">$5.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span17">Seasonal Fruit Tray</span><br />
<span id="Span18">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_12">Mayonaise</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_12">$5.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
</ul>
</div></td></tr>
</table>
</center>
</body>
</html>
这是我正在使用的样式表(primaryStyle.css)
body
{
margin: 20px 0;
padding: 0;
font: Verdana, Arial, Helvetica, sans-serif;
color: #000;
background-attachment: fixed;
text-align: center;
height: 100%;
background: #ABCDEF;
}
.productresultli
{
display: inline;
float: left;
margin-right: 15px;
margin-bottom: 15px;
width: 113px;
padding: 5px;
text-align: center;
}
.productlist
{
float: left;
}
有人知道为什么会发生这种情况吗?任何帮助将不胜感激。如果我不太明白,请告诉我。谢谢!
I'm having a very strange specific problem and I'm going to try to paste the code in here without confusing the issue too much. I've got an unordered list that uses a stylesheet to put each list item into a little square... but after a certain point, the line breaks kind of go nuts. If you add or take away different ones, the line breaks move around and I can't for the life of me figure out what's happening.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<link rel="stylesheet" type="text/css" href="primaryStyle.css" />
</head>
<body>
<center>
<table class="table" border="0" width="750">
<tr>
<td>
<div id="productresults">
<ul class="productlist" >
<li class="productresultli"><center>
<span id="Span3">Seasonal Fruit Tray</span><br />
<span id="Span4">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span5">Seasonal Fruit Tray</span><br />
<span id="Span6">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span17">Seasonal Fruit Tray</span><br />
<span id="Span18">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_12">Mayonaise</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_12">$5.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="Span17">Seasonal Fruit Tray</span><br />
<span id="Span18">$9.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_12">Mayonaise</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_12">$5.00</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_13">Ketchup</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_13">$3.50</span><br /></center>
</li>
<li class="productresultli"><center>
<span id="ContentPlaceHolder1_lvProducts_NameLabel_14">Raspberry Chiptole Sauce</span><br />
<span id="ContentPlaceHolder1_lvProducts_PriceLabel_14">$10.00</span><br /></center>
</li>
</ul>
</div></td></tr>
</table>
</center>
</body>
</html>
This is the stylesheet I'm using (primaryStyle.css)
body
{
margin: 20px 0;
padding: 0;
font: Verdana, Arial, Helvetica, sans-serif;
color: #000;
background-attachment: fixed;
text-align: center;
height: 100%;
background: #ABCDEF;
}
.productresultli
{
display: inline;
float: left;
margin-right: 15px;
margin-bottom: 15px;
width: 113px;
padding: 5px;
text-align: center;
}
.productlist
{
float: left;
}
Does anyone have ANY idea why this is happening? Any help would be appreciated. If I'm not quite making sense, please let me know. THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
li
元素的不同高度导致元素放置不均匀。例如,如果您定义固定高度,例如height:200px
,您会注意到li
正确对齐。由于各个li
的高度不同,并且每个li
都有margin-bottom
,因此列表项将根据可用空间进行排列。设置固定高度,li's
将正确对齐。我为你创建了一个小提琴,供你摆弄 - http://jsfiddle.net/2YSdT/1/
The varying heights of the
li
elements are causing the elements to be placed unevenly. For eg, if you define a fixed height of sayheight:200px
, you'll notice that theli's
align properly. Since the heights of the individualli's
are different and eachli
has amargin-bottom
, the list items are being arranged based on the space available. Set a fixed height and theli's
will align properly.I've created a fiddle for you to well, fiddle with - http://jsfiddle.net/2YSdT/1/
查看您发布的代码后,我认为您所描述的情况是由于未清除浮动造成的。要解决此问题,请将最后一个类添加到每行的最终列表项中。然后使用伪类 :after 清除它们,如下所示。
HTML
CSS
After looking through the code you have posted I think what you are describing is being caused by not clearing your floats. To fix this add the class last to the final list item on each line. Then use the pseudo class :after to clear them such as the following.
HTML
CSS