提问人:user22762966 提问时间:10/24/2023 更新时间:10/24/2023 访问量:8
激活导航栏
Make navigation bar active
问:
我正在尝试使导航栏在我们所在的页面上处于活动状态(例如突出显示)。 例如,如果我们在主页中,它将突出显示主页按钮。例如,当我们在新闻页面中时,我试图让它突出显示导航栏上的新闻按钮
这是我的html代码:
<nav>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<div class="container">
<div class="hamburger" id="hamburger">
<div>
<span class="line-1"></span>
<span class="line-2"></span>
<span class="line-3"></span>
</div>
</div>
</div>
</div>
</label>
<script src="nav.js"></script>
<label class="logo"><a href="index.html">JR-Koders</a></label>
<ul>
<li><a href="index.html" class="text active">Home</a></li>
<li><a href="nav.html" class="text" id="my-news">News</a></li>
<li><a href="#j-koder" class="text">J-Koder</a></li>
<li><a href="#r-koder" class="text">R-Koder</a></li>
<li><a href="#Koders" class="text">Koders</a></li>
<li><a href="#search" id="my-search"><i class="fa fa-search"></i></a></li>
</ul>
</nav>
这是我的CSS代码:
*{
padding: 0;
margin: 0;
text-decoration: none;
list-style: none;
box-sizing: border-box;
font-family: Arial;
}
/* navigation bar */
nav{
background: black;
height: 80px;
width: 100%;
}
.fa-search{
color: white;
}
label.logo{
color: white;
font-size: 35px;
line-height: 80px;
padding: 0 100px;
font-weight: bold;
}
/* n'affecte que le "logo" */
a { color: inherit; }
/* each element at the right of the nav bar */
nav ul li a{
/* color: white; */
font-size: 17px;
text-transform: uppercase;
padding: 7px 13px;
border-radius: 3px;
color: #20C20E;
}
/* n'affecte que les éléments de droite de la nav bar,
.active is the class of the element the user is currently on */
nav ul li a.active, nav ul li a:hover{
background: #20C20E;
color: black;
transition: 1.5s;
}
.checkbtn{
font-size: 30px;
color: white;
float: right;
line-height: 80px;
margin-right: 40px;
cursor: pointer;
display: none;
}
#check{
display: none;
}
/* SMALL SMARTPHONE BEGINNING */
/* If screen is smaller than a normal cellphone, Then make the logo smaller */
@media (max-width: 870px){
label.logo{
font-size: 30px;
padding-left: 25px;
color: white;
}
nav ul li a{
font-size: 16px;
}
}
/* SMALL SMARTPHONE END */
/* NORMAL SMARTPHONE BEGINNING */
@media (max-width: 981px) {
.checkbtn{
display: block;
margin-top: 4.7vh;
margin-right: 7vh;
}
ul{
position: fixed;
width: 100%;
height: 100vh;
background: #2c3e50;
top: 80px;
left: -100%;
text-align: center;
transition: all 0.5s;
}
nav ul li{
display: block;
margin: 50px 0;
line-height: 30px;
}
nav ul li a{
font-size: 20px;
}
a:hover,a.active{
background: none;
color: #20C20E;
background-color: black;
border-radius: 5px;
}
#check:checked ~ ul{
left: 0;
}
label.logo {
color: white;
text-decoration: none;
}
label.a:hover {
background: white;
transition: 3s;
}
/* hamburger BEGINNING */
.container {
width: 0px;
height: 100vh;
background: black;
display: flex;
align-items: center;
justify-content: center;
}
.hamburger, .menu2{
width: 50px;
height: 50px;
margin-top: -735px;
margin-right: -15px;
background-color: #20C20E;
border-radius: 5px;
cursor: pointer;
}
.hamburger div, .menu2 div{
width: 30px;
height: 30px;
margin: 10px;
position: relative;
}
.hamburger span, .menu2 span{
background: #fff;
width: 100%;
height: 2.5px;
border-radius: 5px;
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
transition: transform 0.4s, width 0.5s;
}
/* espace les lignes pour qu'elles ne soient pas les unes sur les autres */
.hamburger .line-1 {
transform: translate(-50%,-12.5px);
}
.hamburger .line-3{
transform: translate(-50%,10px);
}
/* quand le hamburger est en mode croix */
.openhamburger .line-1{
transform: translate(-50%,-50%) rotate(-45deg);
}
.openhamburger .line-3{
transform: translate(-50%,-50%) rotate(45deg);
}
.openhamburger .line-2{
width: 0;
}
/* hamburger END */
}
答: 暂无答案
上一个:移动平均线回溯
评论