用了box-sizing:border-box;后,为li添加右边框,右边框长度超出下边框,怎么解决?

clipboard.png
html代码:
<div class="statisticCharts fdStatistics">

<ul id="selUl1" class="selUl">
    <li>日</li>
    <li>月</li>
    <li>年</li>
    <li>历年</li>
</ul>
<div class="charts"></div>

</div>

css代码:
.content .statisticCharts{

width: 100%;
border-top:1px solid #e7e8e9;

}
.statisticCharts ul{

margin: 0.6rem auto;
width: 90%;
height:1.8rem;
line-height: 1.8rem;
text-align: center;
box-sizing: border-box;
border:1px solid #00aeff;
border-radius: 5px;

}
.statisticCharts ul.selUl li{

float: left;
width:25%;
box-sizing: border-box;
border-right: 1px solid #00aeff;

}
.statisticCharts ul.selUl li:last-child{

border-right: none;

}

阅读 6.3k
3 个回答

看了下在Chrome表现正常,在Firefox就出现border超过元素的现象,应该是浏览器处理盒模型的方式存在差异引起的。
解决:给ul加上overflow: hidden即可

.statisticCharts ul{
margin: 0.6rem auto;
width: 90%;
height:1.8rem;
line-height: 1.8rem;
text-align: center;
box-sizing: border-box;
border:1px solid #00aeff;
border-radius: 5px;
overflow: hidden /* 给外层ul加上即可 */
}
.statisticCharts ul {
    margin: 0.6rem auto;
    width: 90%;
    /* height: 1.8rem; */  /*不要定义高度*/
    /* line-height: 1.8rem; */
    text-align: center;
    box-sizing: border-box;
    border: 1px solid #00aeff;
    border-radius: 5px;
    overflow: hidden;/*让float:left的元素不塌陷*/
}

ul的高改成 height:1.85rem 就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题