我正在尝试使标题的边框顶部具有一种颜色,并且当悬停/激活导航时,它的一部分会变为另一种颜色。
以及为什么对于li:hover
标签,当我执行border-top
时仍返回border-bottom
吗?
What I'm trying to achieve in a picture
如前所述,我还希望在hover
上,边框过渡位于图片中绿色边框线的上方。
我怎样才能做到这一点?
这是我到目前为止的
/*** Page ***/
html,body {
margin: 0;
}
/*** Navigation ***/
.navbar {
background-color: #ecf0f1;
}
.navbar > .main-nav > ul,
li {
list-style-type: none;
text-decoration: none;
}
.navbar > .main-nav > ul {
min-height: 60px;
margin: 0;
padding: 0;
overflow: hidden;
box-sizing: border-box;
border-top: 8px solid #d1d064;
}
.navbar > .main-nav > ul > li {
text-align: center;
min-width: 150px;
position: relative;
top: -2px;
display: block;
float: left;
}
.navbar > .main-nav > ul > li a {
display: block;
color: #737373;
text-align: center;
padding: 20px 16px;
text-decoration: none;
font-family: 'Lato', sans-serif;
font-weight: 800;
}
.navbar > .main-nav > ul > li.active {
border-top: 8px solid #0F9E5E;
}
.navbar > .main-nav > ul > li:after {
display: block;
content: '';
border-top: solid 3px #a8a8b6;
transform: scaleX(0);
transition: transform 250ms ease-in-out;
}
.navbar > .main-nav > ul > li:hover:after {
transform: scaleX(1);
}
.navbar > .main-nav {
max-width: 1480px;
margin: 0 auto;
}
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/hover.css/2.1.0/css/hover-min.css" rel="stylesheet">
</head>
<body>
<br><br><br><br><br><br>
<nav class="navbar">
<div class="main-nav">
<ul>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Second</a></li>
<li><a href="#">Third</a></li>
</ul>
</div>
</nav>
</body>
谢谢
最佳答案
边框会影响布局,我建议您只需切换到box-shadow
即可更改颜色:
.navbar > .main-nav > ul > li.active,
.navbar > .main-nav > ul > li:hover {
box-shadow: 0 -8px 0 #0F9E5E;
}
工作演示:
.navbar {
background-color: #ecf0f1;
}
.navbar::after {
content: '';
clear: both;
display: block;
}
.navbar > .main-nav > ul,
li {
list-style-type: none;
text-decoration: none;
}
.navbar > .main-nav > ul {
margin: 0;
padding: 0;
box-sizing: border-box;
border-top: 8px solid #d1d064;
}
.navbar > .main-nav > ul > li {
text-align: center;
min-width: 150px;
position: relative;
display: block;
float: left;
}
.navbar > .main-nav > ul > li a {
display: block;
color: #737373;
text-align: center;
padding: 20px 16px;
text-decoration: none;
font-family: 'Lato', sans-serif;
font-weight: 800;
}
.navbar > .main-nav > ul > li.active,
.navbar > .main-nav > ul > li:hover {
box-shadow: 0 -8px 0 #0F9E5E;
}
<br>
<br>
<br>
<nav class="navbar">
<div class="main-nav">
<ul>
<li class="active"><a href="#">Home</a>
</li>
<li><a href="#">Second</a>
</li>
<li><a href="#">Third</a>
</li>
</ul>
</div>
</nav>
这是由以下CSS引起的:
.navbar > .main-nav > ul > li:after {
display: block;
content: '';
border-top: solid 3px #a8a8b6;
transform: scaleX(0);
transition: transform 250ms ease-in-out;
}
.navbar > .main-nav > ul > li:hover::after {
transform: scaleX(1);
}
关于html - 如何使边界重叠?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41205415/