我是初学者,我正在为我的一个学校网络项目编写一个网站 . 我正在尝试设置 Headers 样式,使它看起来像这样:
https://i.stack.imgur.com/Wz58F.png
但导航和"sign up for a library card"按钮给了我一些问题 . 我想将按钮移到它顶部的图标下面,但按钮一直向左移动 . 我试过 float: right ,但那不是我的html和CSS . 谢谢!
</head>
<body>
<header>
<img class="logo clearfix" src="images/logo.png" alt="Charlotte County Library System Logo"/>
<img class="icons right clearfix" src="images/search.png" alt="Search Icon"/>
<img class="icons right clearfix" src="images/myaccount.png" alt="My Account Icon"/>
<button class="signup">Sign Up for a Library Card ></button>
</header>
<div class="nav">
<nav>
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="index.html">CATALOG</a></li>
<li><a href="index.html">FEES & FINES</a></li>
<li><a href="index.html">LOCATIONS & HOURS</a></li>
<li><a href="index.html">SERVICES</a></li>
</ul>
</nav>
</div>
</body>
</html>
CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.clearfix:after{
content:"";
display: table;
clear: both;
}
header{
width: 1200px;
margin: 0 auto;
margin-bottom: 40px;
}
.logo{
float: left;
width: 400px;
margin-top: 30px;
}
.icons{
width: 45px;
padding: 10px;
}
.left{
float:left;
}
.right{
float: right;
}
button {
background-color: #3399CC;
border: none;
border-radius: 4px;
color: #fff;
padding: 8px;
width: 250px;
text-align: center;
text-decoration: none;
font-size: 14px;
margin-top: 70px;
font-family:'Poppins', sans-serif;
font-weight: 500;
cursor: pointer;
}
nav{
background-color: #13DEA9;
width: 100%;
}
nav ul{
padding: 15px;
}
nav ul li{
font-family: 'Poppins', sans-serif;
font-weight: 600;
text-align: center;
list-style: none;
display: inline;
}
nav ul li a{
text-decoration: none;
margin: 70px;
color: white;
}
1 回答
只需使用flexbox . 这是你的新css
这是一个JS小提琴:https://jsfiddle.net/jot6L15b/
另外,我为
nav
添加了一个height属性,您可以将其设置为您想要的任何值,它也将保持垂直居中 .