您的位置:首页 > Web前端 > HTML

如何去除html代码标签之间换行产生的空格

2016-10-10 10:54 1036 查看
参考链接:5种方法去掉HTML中Inline-Block元素之间的空白

当使用inline-block时,HTML元素之间的空白会显示在页面上,为了保持代码的美观,不建议使用全部写在一行内或者影响美观的方法。

推荐方法:在父元素上设置
font-size: 0;

例:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
div {
height: 41px;
border-top: 4px solid red;
border-bottom: 1px solid gray;
}
a {
display: inline-block;
height: 41px;
text-align: center;
line-height: 41px;
text-decoration: none;
padding: 0px 5px;
background-color: red;
font-size: 14px;
font-family: 楷体;
}
.shouye {
margin-left: 200px;
}
.shouye:hover {
background-color: gray;
}
</style>
</head>
<body>
<div>
<a class="shouye" href="#">设为首页</a>
<a href="#">手机新浪网</a>
<a href="#">移动客户端</a>
</div>
</body>
</html>


效果预览:



修改后代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
div {
font-size: 0;/*关键代码*/
height: 41px;
border-top: 4px solid red;
border-bottom: 1px solid gray;
}
a {
display: inline-block;
height: 41px;
text-align: center;
line-height: 41px;
text-decoration: none;
padding: 0px 5px;
background-color: red;
font-size: 14px;
font-family: 楷体;
}
.shouye {
margin-left: 200px;
}
.shouye:hover {
background-color: gray;
}
</style>
</head>
<body>
<div>
<a class="shouye" href="#">设为首页</a>
<a href="#">手机新浪网</a>
<a href="#">移动客户端</a>
</div>
</body>
</html>


效果预览:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: