javascript - dropdown isn't appearing on hover -
i've written primitive navbar. reading code seems logical , correct code doesn't work - when move cursor on "news" bar dropdown menu doesn't appear. missing?
<!doctype html> <html> <head> <title>learning</title> <style> body{ margin: 0px;} body { display: inline-block; width:25%; padding: 14px 0px; margin: 0px; background-color: rgb(0,0,255); color: white; text-align: center; float: left; font-size: 1.5em; text-decoration: none;} .dropdown-content { display: none; position: absolute; background-color: rgb(0,0,255); color: white; min-height: 50px; width: 25%;} .dropdown-content { display: block; color:white; text-decoration: none; padding: 20px 0px; text-align: center;} a.dropdown:hover .dropdown-content{ display: block;} body > a:hover, .dropdown-content a:hover{ background-color: rgb(0,0,128);} </style> </head> <body> <a href="#">home</a> <a href="#">test</a> <a href="#" class="dropdown">news</a> <div class="dropdown-content"> <a href="http://www.cnn.com">cnn</a> <a href="http://www.bbc.com">bbc</a> </div> <a href="#">about</a> </body> </html>
this 1 should started:
https://jsfiddle.net/kezpw1e7/
i modified of css , html. dropdown works now, you'll need adjust widths , of styling.
<style> body{ margin: 0px;} .nav { width:100%; } div { display: inline-block; /*width:25%;*/ padding: 14px 0px; margin: 0px; background-color: rgb(0,0,255); color: white; text-align: center; float: left; font-size: 1.5em; text-decoration: none;} .dropdown { position:relative; } .dropdown-content { display: none; position: absolute; background-color: rgb(0,0,255); color: white; min-height: 50px; /*width: 25%;*/ top:53px; left:0px;} .dropdown-content { display: block; color:white; text-decoration: none; padding: 20px 0px; text-align: center;} div.dropdown:hover .dropdown-content{ display: block;} body > div:hover, .dropdown-content div:hover{ background-color: rgb(0,0,128);} </style> <div class="nav"> <div href="#">home</div> <div href="#">test</div> <div href="#" class="dropdown">news <div class="dropdown-content"> <a href="http://www.cnn.com">cnn</a> <a href="http://www.bbc.com">bbc</a> </div> </div> <div href="#">about</div> </div>
Comments
Post a Comment