我遇到了在CSS中使用属性"float“的问题。在页面顶部出现10 On边距。怎么修呢?
PS.Adding空div到带有id="background1“的父div不起作用--我还读过本文https://css-tricks.com/all-about-floats/,但不知道如何应用这些技术来清除浮动
body{
margin: 0;
padding: 0;
font-family: sans-serif;
}
#background1 {
background: #F6F7FB;
width: 100%;
height: 527px;
padding:0;
position: relative;
}
/*Header menu*/
#background1 li {
list-style-type: none;
display:inline;
}
#background1 li a {
font-family: HalisGR-Medium;
font-size: 20px;
color: #3B3B3B;
text-decoration: none;
float: right;
margin-left: 52px;
margin-top: 24px;
}
#navmenu {
margin-right: 72px;
}
/*Header menu ends*/<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!--Header menu-->
<div id="background1" style="clear: both">
<div style="clear: both;"></div>
<section id="navmenu">
<ul>
<li><a href="#">Projects</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</section>
</div>
</body>
</html>
发布于 2017-03-10 05:20:36
不是因为漂浮的孩子。只需将margin:0;应用于ul即可。margin-top是在父进程之外崩溃和显示的内容。
body{
margin: 0;
padding: 0;
font-family: sans-serif;
}
#background1 {
background: #F6F7FB;
width: 100%;
height: 527px;
padding:0;
position: relative;
}
/*Header menu*/
#background1 li {
list-style-type: none;
display:inline;
}
#background1 li a {
font-family: HalisGR-Medium;
font-size: 20px;
color: #3B3B3B;
text-decoration: none;
float: right;
margin-left: 52px;
margin-top: 24px;
}
#navmenu {
margin-right: 72px;
}
#navmenu ul {
margin: 0;
}
/*Header menu ends*/<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!--Header menu-->
<div id="background1" style="clear: both">
<div style="clear: both;"></div>
<section id="navmenu">
<ul>
<li><a href="#">Projects</a></li>
<li><a href="#">Bio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</section>
</div>
</body>
</html>
https://stackoverflow.com/questions/42710774
复制相似问题