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 to default dimensions, so you can not add more items or resize by keeping effect .
What I would like is to have this same effect in a traditional, fluid, flexible, no-dimensioned menu 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>
Sample 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>
Source 1: link
Source 2: link