I know this is pretty basic, but it is giving me hangups. I have a basic list:
我知道这是非常基本的,但它给了我挂机。我有一个基本清单:
<ul>
<li><a href="#">Insert Link Here</a></li>
<li><a href="#">Insert Link Here</a></li>
<li><a href="#">Insert Link Here</a></li>
</ul>
What do I need to do to make sure the last <li>
item gets cleared? I've tried adding style="clear:both" to the end with no avail. Also I've added a 'div' after the last <li>
tag before the closing </ul>
tag, that works, but I know it doesn't validate.
我需要做些什么来确保最后一个
2 个解决方案
#1
30
If you want to have the background behind a block item which has only floated items inside, then:
如果你想在一个只有浮动项目的块项目后面有背景,那么:
ul {
overflow: auto;
}
#2
1
Given that you've found "[adding] a div
after the last <li>
...works" why not try adding another <li>
, give it a class-name of, for example clearing
and:
鉴于您在最后一个
li.clearing {display: block; clear: both; }
If you need this to take up little, or no, room then adding height: 0; background-color: transparent; border: 0 none transparent;
should prevent its being visible, while still causing the clearing to occur.
如果你需要这个占用很少或没有房间,那么增加高度:0;背景颜色:透明;边框:0无透明;应该防止其可见,同时仍然导致清除。
It would almost certainly be a benefit if you could add your use-case, and explain, as the comment asked: what do you want? (and I say that with trepidation, after watching too much Babylon 5 recently).
如果你可以添加你的用例几乎肯定是一个好处,并解释,评论问:你想要什么? (最近我看了太多的巴比伦5后,我惶恐地说)。
#1
30
If you want to have the background behind a block item which has only floated items inside, then:
如果你想在一个只有浮动项目的块项目后面有背景,那么:
ul {
overflow: auto;
}
#2
1
Given that you've found "[adding] a div
after the last <li>
...works" why not try adding another <li>
, give it a class-name of, for example clearing
and:
鉴于您在最后一个
li.clearing {display: block; clear: both; }
If you need this to take up little, or no, room then adding height: 0; background-color: transparent; border: 0 none transparent;
should prevent its being visible, while still causing the clearing to occur.
如果你需要这个占用很少或没有房间,那么增加高度:0;背景颜色:透明;边框:0无透明;应该防止其可见,同时仍然导致清除。
It would almost certainly be a benefit if you could add your use-case, and explain, as the comment asked: what do you want? (and I say that with trepidation, after watching too much Babylon 5 recently).
如果你可以添加你的用例几乎肯定是一个好处,并解释,评论问:你想要什么? (最近我看了太多的巴比伦5后,我惶恐地说)。