3
In the example below we have an interesting menu, with a effect Hover, which follows the mouse and its items. Everything is very beautiful and works well. The problem is that this menu is set with default dimensions, cannot add more items or change the size keeping the effect.
What I’d like is to have that same effect in a traditional menu, fluid, flexible, without defined dimensions, without :Nth-Child
@import url(https://fonts.googleapis.com/css?family=Roboto:100);
body {
font-family:'HelveticaNeue-UltraLight', 'Helvetica Neue UltraLight', Roboto, Arial, Sans-serif;
background:#ecf0f1;
}
nav {
width:400px;
height:60px;
margin:125px auto 0;
text-align:center;
background:#fff;
box-shadow:0 1px 2px #ddd;
backface-visibility:hidden;
}
nav ul {
position:relative;
}
nav ul li {
display:inline-block;
line-height:60px;
width:100px;
margin-right:-4px;
}
nav ul li:first-child {
margin-left:-4px;
}
li:nth-child(4):after {
content:"";
width:100px;
height:3px;
position:absolute;
background:#3498db;
top:0;
left:0;
transform:translateX(0);
transition:.5s;
}
nav ul li:nth-child(2):hover ~ li:nth-child(4):after { transform:translateX(100px); }
nav ul li:nth-child(3):hover ~ li:nth-child(4):after { transform:translateX(200px); }
nav ul li:nth-child(4):hover:after { transform:translateX(300px); }
nav ul li a {
text-decoration:none;
color:#2c3e50;
cursor:pointer;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<nav>
<ul>
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Clients</a></li>
<li><a>Work</a></li>
</ul>
</nav>
Example menu where I would like the effect of the above example to be applied.
.dropdownmenu ul, .dropdownmenu li {
margin: 0;
padding: 0;
}
.dropdownmenu ul {
background: gray;
list-style: none;
width: 100%;
}
.dropdownmenu li {
float: left;
position: relative;
width:auto;
}
.dropdownmenu a {
background: #30A6E6;
color: #FFFFFF;
display: block;
font: bold 12px/20px sans-serif;
padding: 10px 25px;
text-align: center;
text-decoration: none;
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
.dropdownmenu li:hover a {
background: #000000;
}
#submenu {
left: 0;
opacity: 0;
position: absolute;
top: 35px;
visibility: hidden;
z-index: 1;
}
li:hover ul#submenu {
opacity: 1;
top: 40px; /* adjust this as per top nav padding top & bottom comes */
visibility: visible;
}
#submenu li {
float: none;
width: 100%;
}
#submenu a:hover {
background: #DF4B05;
}
#submenu a {
background-color:#000000;
}
<nav class="dropdownmenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Me</a></li>
<li><a href="#">Articles on HTML5 & CSS3</a>
<ul id="submenu">
<li><a href="#">Difference between SVG vs. Canvas</a></li>
<li><a href="#">New features in HTML5</a></li>
<li><a href="#">Creating links to sections within a webpage</a></li>
</ul>
</li>
<li><a href="#">News</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
simply magnificent. that’s exactly it! The effect is fixed on the link Home this effect should also be active on the page of the respective link opened.
li.current-link
– John Quimera
I understand what I need to do.
– John Quimera
I messed up, misjudged the code, tried, but couldn’t...
– John Quimera
was perfect.
– John Quimera
https://answall.com/q/285555/95735
– John Quimera
it will be possible to put also that same effect, with the and event phocus ? same as css.
– John Quimera
the issue of Focus/active for that menu, it would be necessary to ask a new question?
– John Quimera
does not work, I also tested with mousedown, and only click works. But Hover does not. You cannot use these values together?
mouseover
andmousedown
– John Quimera
Here it works: https://jsfiddle.net/q488npqp/
– Sam
including Hover? Because only click works here.
– John Quimera
I’ll ask another question.
– John Quimera
I understand. Indeed, but the main one is only the contextmenu.
Abrir em nova aba.
– John Quimera