ul li列表元素浮动导致border没有底边解决办法

时间:2023-11-30 19:10:44

ul li列表元素浮动导致border没有底边解决办法

如图,当ul li,li元素浮动,并且ul元素也overflow:hidden清除浮动的时候,给li元素加了border,但是不显示底边,这时候要看是不是没有给li元素加高,因为加了border之后默认li的高度会继承ul的,再加上border的像素则超出了ul的高度,而高度设置了overflow:hidden;所以被遮盖住了其中一个边。

ul{
width:60%;
margin:0 auto;
overflow: hidden;
box-sizing: border-box;
height:50px;
line-height:50px;
border-radius: 5px;
text-align: center;
}
li{
width:50%;
box-sizing: border-box;
float: left;
border:2px solid @pubColor;
color:@pubColor;
background-color:#fff;
/*height:50px;*/
/*line-height:50px;*/
}

当ul有高,li也加了高了之后就可以正常显示border了,最终li元素高度为本身高度+border高度=ul的高度。