我希望包含链接的主导航位于电话媒体的中间我使用边距:自动;但这没有用。我在悬停时使用 ::before 来获得一些效果。
这是 HTML 代码:
<div class="header">
<div class="container">
<a href="#" class="logo">Abuissa</a>
<nav>
<ul class="main-nav">
<li><a href="#article">Article</a></li>
<li><a href="#gallery">Gallery</a></li>
<li><a href="#feauters">Feauters</a></li>
<li><a href="#">Other Skills</a></li>
</ul>
</nav>
</div>
</div>
这是 CSS 代码:
/* Start Header */
.header {
background-color: white;
box-shadow: 0 0 10px #ddd;
-webkit-box-shadow: 0 0 10px #ddd;
-mox-box-shadow: 0 0 10px #ddd;
position:relative;
}
.header .container {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
position: relative;
}
.header .logo {
color: var(--main-color);
font-size: 26px;
font-weight: bold;
height: 72px;
display: flex;
justify-content: center;
align-items: center;
}
@media (max-width:767px) {
.header .logo {
width: 100%;
height: 50px;
}
}
.header .main-nav {
display: flex;
}
@media (max-width: 767px) {
.heade .main-nav {
margin: auto;
}
}
.header .main-nav > li > a {
display: flex;
justify-content: center;
align-items: center;
height: 72px;
position: relative;
color: black;
padding: 30px;
transition: var(--main-transition);
overflow: hidden;
}
@media (max-width:767px) {
.header .main-nav > li > a {
padding: 10px;
font-size: 14px;
height: 40px;
}
}
.header .main-nav > li > a::before {
content: "";
position: absolute;
width: 100%;
height: 3px;
background-color: var(--main-color);
top: 0;
left: -100%;
transition: var(--main-transition);
}
.header .main-nav > li > a:hover {
color: var(--main-color);
background-color: #fafafa;
}
.header .main-nav > li > a:hover::before {
left: 0%;
}
/* End Header */