【发布时间】:2020-07-03 20:34:32
【问题描述】:
我正在尝试使用 CSS 布局创建一个标题,但我无法将我的“联系人”元素放置在它的容器“主导航”的最右侧。我在 html 和 css 代码中尝试了以下内容,但“contacts”元素仍然位于“main-nav”容器中的其他元素所在的位置。请帮忙! PS:我是开发新手。我希望我能很好地解释我的烦恼。谢谢
<!DOCTYPE html>
<html>
<head>
<title>MY WEB LAYOUT</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<nav class="zone green">
<ul class="main-nav">
<li><a href="">About</a></li>
<li><a href="">Products</a></li>
<li><a href="">Our Team</a></li>
<li class="push"><a href="">Contacts</a></li>
</ul>
</nav>
<div class="zone red">Cover</div>
<div class="zone blue">Project Grid</div>
<div class="zone yellow">Footer</div>
</body>
</html>
/* CSS */
body {
margin: auto 0;
}
.zone {
/*padding: 30px 50px;
margin: 40px 60px;*/
cursor:pointer;
/*display:inline-block;*/
color: #FFF;
/*text-align: center;*/
font-size:2em;
border-radius:4px;
border:1px solid #bbb;
transition: all 0.3s linear;
}
.zone:hover {
-webkit-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
-moz-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
-o-box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
box-shadow:rgba(0,0,0,0.8) 0px 5px 15px, inset rgba(0,0,0,0.15) 0px -10px 20px;
}
/* NAV */
.main-nav {
display: flex;
list-style: none;
font-size: 0.7em;
margin: 0;
}
.contacts {
display: flex;
justify-content: space-between;
align-items: center;
}
.push {
display: flex;
float: right;
justify-content: flex-end;
margin-left: auto;
}
li {
padding: 20px;
}
a {
color: #f5f5f6;
text-decoration: none;
}
【问题讨论】: