1
I have a traditional header, which thanks to @hugocsl, who helped me in that question, a color transition occurs when a menu item is in hover
. Everything works very well, what I want now is to maintain the same effect, beyond the hover
, also with focus/active
h1 {
padding: 0;
margin: 0;
color: #fff
}
header {
padding: 0;
margin: 0;
position: relative;
}
header::after {
content: "";
position: absolute;
background: gray;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -2;
}
.header-content {
/* background: gray; */
padding: 30px;
}
.nav {
background: #333;
height: 60px;
/* position: relative; */
}
.nav ul {
float: left;
}
.nav ul,
.nav ul li {
line-height: none;
padding: 0;
margin: 0;
}
.nav ul li {
display: inline-block;
/* position: relative; */
vertical-align: top;
}
/* cores no hover */
.nav ul li:hover::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
transition: 1s;
}
.nav ul li#menu-item-1:hover::after {
background: gray;
}
.nav ul li#menu-item-2:hover::after {
background: green;
}
.nav ul li#menu-item-3:hover::after {
background: blue;
}
.nav ul li#menu-item-4:hover::after {
background: red;
}
.nav ul li#menu-item-5:hover::after {
background: gold;
}
.nav ul li#menu-item-6:hover::after {
background: lime;
}
.nav ul li a {
display: block;
line-height: 60px;
text-decoration: none;
padding: 0 30px;
color: #fff;
}
.nav ul li a:hover {
color: #AAA
}
<header>
<div class="header-content">
<h1 class="logo">Header Colorido on Hover</h1>
</div>
<nav class="nav">
<ul>
<li class="menu-item" id="menu-item-1"><a href="#">Header Cinza</a></li>
<li class="menu-item" id="menu-item-2"><a href="#">Verde</a></li>
<li class="menu-item" id="menu-item-3"><a href="#">Azul</a></li>
<li class="menu-item" id="menu-item-4"><a href="#">Vermelho</a></li>
<li class="menu-item" id="menu-item-5"><a href="#">Gold</a></li>
<li class="menu-item" id="menu-item-6"><a href="#">Lime</a></li>
</ul>
</nav>
</header>
Using Hover will only be possible with Javascript (including or not libs like jQuery, Angular, etc).
– Guilherme Nascimento
@Guilhermenascimento with so much that this structure is maintained, I see no problem in using javascript, can be pure or jquery.
– John Quimera
I was just commenting to be upfront that CSS will only not achieve this, if it was with the click I could even simulate, but not.
– Guilherme Nascimento