遇到一个这样的问题,当我们把div标签的display设置为inline-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;
}
.main {
margin: 50px;
}
.left {
width: 100px;
height: 60px;
background-color: blue;
display: inline-block;
}
.right {
width: 200px;
height: 70px;
background-color: yellow;
display: inline-block;
}
</style>
</head>
<body>
<div class="main">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
页面显示:
解决办法:
第一种解决办法:
两个行内框的父元素设置 font-size:0 的属性,就可以解决,如果行内框有文字要展示,可以在给行内框设置字体大小。
第二种解决办法:
第三种解决办法: