我有一个导航栏,当悬停列表中的任何项目时,我在底部添加了一条红线,但我想将该红线移到标题下方(例如“服务”),知道如何实现此目的?
我在 codepen 中添加了一个小示例,以便您可以轻松检查 HTML 和 CSS 代码
header {
background-color: lightblue;
padding-top: 1rem;
position: sticky;
top: 0;
display: flex;
align-items: center;
justify-content: space-around;
}
header nav {
min-width: 50%;
}
header nav ul {
margin: 0;
height: 100%;
list-style: none;
padding-left: 0;
display: flex;
align-items: center;
justify-content: space-between;
}
header li:hover {
height: 100%;
border-bottom: 2px solid red;
}
Whatever logo
CONTACT
查看代码的链接
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我认为只需为所有列表元素提供与标题相同的高度即可。
像这样:-
header { background-color: lightblue; padding-top: 1rem; height: 3rem; position: sticky; top: 0; display: flex; align-items: center; justify-content: space-around; } header nav { min-width: 50%; height : 100%; } header nav ul { margin: 0; height: 100%; list-style: none; padding-left: 0; display: flex; align-items: center; justify-content: space-between; } header li{ height: inherit; } header li:hover { border-bottom: 2px solid red; }Whatever logo
CONTACT