简体   繁体   English

如果Li的样式为“float:left;”,如何为UL创建边框?

[英]How to make border for UL if Li has style “float:left;”?

My css for ul is: 我对ul的css是:

ul {list-style-type: none; margin:auto; border-top: 1px solid #0093a7; border-bottom: 1px solid #0093a7; margin: 20px 0;}
ul li {float:left; padding:5px;}

The UL tag: UL标签:

<ul>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
      <li><a href="#">Link</a></li>
</ul>

Now both borders are on the top of the UL. 现在两个边界都在UL的顶部。 How to make bottom border then? 如何制作底部边框呢?

You need to apply overflow:hidden to your ul so that your floats are cleared and are contained within the ul . 您需要对您的ul应用overflow:hidden ,以便清除浮动并包含在ul

Currently your ul is collapsing since it contains only floated elements. 目前你的ul正在折叠,因为它只包含浮动元素。

If you need to support IE6(?!) then you will need to make sure your container (ie. ul ) hasLayout for the overflow trick to work. 如果你需要支持IE6(?!)那么你需要确保你的容器(即ul )hasLayout以便溢出技巧起作用。 You can do this by applying a width. 您可以通过应用宽度来完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM