我想将菜单上方的悬停水平条/边框居中。 (我已经尝试过text-align:center和align-content)。我怎么能这样做?
这是我的代码:
nav ul {
list-style-type: none;
display: flex;
}
nav li {
margin-right: 15px;
margin-top: 5px;
}
nav a {
font-size: 1.1em;
color: #181818;
padding-right: 20px;
padding-top: 30px;
text-decoration: none;
}
nav a:hover {
color: black;
border-top: 3px solid #3691b0;
text-align: center;
}
nav {
position: absolute;
right: 210px;
top: 20px;
}
<nav>
<ul>
<li><a href="#">Accueil</a></li>
<li><a href="nos services.html">Services</a></li>
<li><a href="nos projets.html">Portfolio</a></li>
<li><a href="formulaire.html">Contact</a></li>
</ul>
</nav>
感谢您的帮助
答案 0 :(得分:0)
如果你添加了导航a {padding-right:20px;在<a>center </a>
内创建一些空格,除非你使两边都相等填充
尝试将其更改为margin-right:20px;
nav ul {
list-style-type: none;
display: flex;
}
nav li {
margin-right: 15px;
margin-top: 5px;
}
nav a {
font-size: 1.1em;
color: #181818;
margin-right:20px; //padding-right:20px;
padding-top: 30px;
text-decoration: none;
}
nav a:hover {
color: black;
border-top: 3px solid #3691b0;
text-align: center;
}
nav {
position: absolute;
right: 110px;
top: 50px;
}
<nav>
<ul>
<li><a href="#">Accueil</a></li>
<li><a href="nos services.html">Services</a></li>
<li><a href="nos projets.html">Portfolio</a></li>
<li><a href="formulaire.html">Contact</a></li>
</ul>
</nav>