display:inline-block显示缝隙问题的解决🤓🤓
问题:
我们在日常使用display:inline-block的时候,往往会遇到如下情况:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.space p{
display: inline-block;
width: 50px;
height: 50px;
background-color: green;
}
</style>
</head>
<body>
<div class="space">
<p>1</p>
<p>2</p>
<p>3</p>
</div>
</body>
</html>

如何解决呢?
提供如下几种方法:
- 将每个设置
display:inline-block的margin设置为负值。- 将父元素的
font-size设置为0
🤓🤓🤓🤓🤓在这里插入代码片
在CSS布局中,当使用display:inline-block时可能会遇到元素间存在缝隙的问题。这个问题可以通过设置负margin或者将父元素的font-size设为0来解决。文章提供了这两种常见的解决方法。
3022

被折叠的 条评论
为什么被折叠?



