下方也出现了间隙
网上找了一圈,全是说inline-block的,但是我调整a标签为block还是有间隙。
问题代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
background-color: #dddddd;
}
.flex-col{
display: flex;
flex-direction: column;
}
.category{
width: 100px;
border: 2px solid black;
border-radius: 8px;
overflow: hidden;
padding: 0;
margin-left: 16px;
background-color: white;
box-sizing: border-box;
/* 改了block,调了fontsize,还是有间隙 */
font-size: 0;
/* word-spacing: -2px;*/
}
.category a{
font-size: 16px;
display: block;
text-align: center;
color: #363636;
padding: 8px;
}
.category a:hover{
color: white;
background-color: #4582ec;
}
</style>
</head>
<body>
<div class="category flex-col">
<a href="#">编程</a>
<a href="#">编程</a>
<a href="#">编程</a>
<a href="#">编程</a>
<a href="#">编程</a>
<a href="#">编程</a>
</div>
</body>
</html>
尝试
我把border取消后,发现空隙似乎消失了,于是开始调border
- 调小border
当调border为1px时,左边空隙消失,下方仍有间隙
- 调大border
border为3px时,右侧也出现了间隙 - 调非常大
border为12px时,所有间隙都消失 - ...
结论
border的值设置为4px的倍数时,不会产生间隙。
标签:容器,间隙,color,编程,background,border,block From: https://www.cnblogs.com/oldsaltfish/p/18171314