javascript - HTML or CSS navigation bar issue -


basically, have created navigation bar has underline when hovered , when active. have line spanning page. when cursor hovered on list, 4px line appears under word pushed line spanning page down 4 pixels. can please.

here's html:

<!doctype html> <head>     <meta name="viewport" content="width=device-width, initial-scale=1">     <title>home</title>     <link rel="stylesheet" href="new1.css"> </head> <body>     <nav id="ddmenu">         <div class="menu-icon"></div>         <ul>             <li class='top-heading'><a href='#'><span>new in</span></a>             </li>             <li class='top-heading'><a href='#'><span>homeware</span></a>             </li>             <li class='top-heading'><a href='#'><span>decorating</span></a>             </li>             <li class='top-heading'><a href='#'><span>diy</span></a>             </li>             <li class='top-heading'><a href='#'><span>furniture</span></a>             </li>             <li class='top-heading'><a href='#'><span>bathroom</span></a>             </li>             <li class='top-heading'><a href='#'><span>garden</span></a>             </li>             <li class='top-heading'><a href='#'><span>offers</span></a>             </li>         </ul>     </nav> </body> </html> 

here's css

#ddmenu {   zoom: 1;   width: 100%;   background: #fff;   padding: 0px 0; } #ddmenu:before {   content: '';   display: block; } #ddmenu:after {   content: '';   display: block;   clear: both; } #ddmenu ul {   list-style-type: none;   position: relative;   display: block;   font-size: 12px;   font-family: verdana, helvetica, arial, sans-serif;   margin: 0px;   padding-top: 4px;   border-bottom: 1px solid #eaebeb;   border-top: 1px solid #eaebeb;   zoom: 1; } #ddmenu ul:before {   content: '';   display: block; } #ddmenu ul:after {   content: '';   display: block;   clear: both; } #ddmenu li {   display: block;   float: left;   margin: 0;   padding: 0; } #ddmenu li {   float: left;   color: #000;   text-decoration: none;   height: 20px;   padding: 1px 50px 0;   font-weight: normal; } #ddmenu li:hover, #ddmenu .active {   text-decoration: none;   border-bottom: 4px solid #eaebeb;   colour: #000 } #ddmenu .active {   font-weight: 700; } 

when add border you're increasing height of element naturally affects items below it.

without set height optimal solution have border there transparent , change color on hover.

#ddmenu li {   display: block;   float: left;   margin: 0;   padding: 0;   border-bottom:4px solid transparent; } 

jsfiddle demo

note: suggestion have lot of padding on links there. can see in doesn't quite nice @ smaller viewports...you might want that.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -