Emin Eryilmaz Emin Eryilmaz - 3 months ago 6
HTML Question

Hoverable Dropdown

I tried to make a Hoverable text, but it gives me a little visual error. I want to make it in this way: http://i.imgur.com/fg1NTab.png

but at my website it gives in this way.

http://vestigedayz.com/wqeq

(press on the A from menu on my website)

This is my CODE.

<div class="liste">
<div class="dropdown">
<ul> <li><a href="#">A</a></li> </ul>
<div class="dropdown-content">
<li><a href="#">AA</a></li>
<li><a href="#">AB</a></li>
<li><a href="#">AC</a></li>
<li><a href="#">AD</a></li>
</div>
</div>

<ul> <li><a href="#">B</a></li> </ul>

<ul> <li><a href="#">c</a></li> </ul>
<ul> <li><a href="#">d</a></li> </ul>
<ul> <li><a href="#">e</a></li> </ul>
<ul> <li><a href="#">f</a></li> </ul>
<ul> <li><a href="#">g</a></li> </ul>
<ul> <li><a href="#">h</a></li> </ul>
<ul> <li><a href="#">i</a></li> </ul>
<ul> <li><a href="#">j</a></li> </ul>
<ul> <li><a href="#">k</a></li> </ul>
<ul> <li><a href="#">l</a></li> </ul>
<ul> <li><a href="#">m</a></li> </ul>
<ul> <li><a href="#">n</a></li> </ul>
<ul> <li><a href="#">o</a></li> </ul>
<ul> <li><a href="#">p</a></li> </ul>
<ul> <li><a href="#">q</a></li> </ul>
<ul> <li><a href="#">r</a></li> </ul>
<ul> <li><a href="#">s</a></li> </ul>
<ul> <li><a href="#">t</a></li> </ul>
<ul> <li><a href="#">u</a></li> </ul>
<ul> <li><a href="#">v</a></li> </ul>
<ul> <li><a href="#">w</a></li> </ul>
<ul> <li><a href="#">y</a></li> </ul>
<ul> <li><a href="#">z</a></li> </ul>
</div>
</div>
</div>


AND THE STYLE CSS

.header .liste {background:#ffd564;border-bottom:5px solid #ffecb8;font-size:13px;height:50px;overflow:hidden;padding-left:25px;margin-top:30px;}
.header .liste > ul li {float:left;padding-right:30px;margin:17px 0;}
.header .liste > ul li a {text-decoration:none;color:#1b1b1b;text-transform:uppercase;}
.dropdown {
position: fixed;
display: table;
}



.dropdown-content {
display: none;
position: absolute;
background-color: #ffecb8;
min-width: 950px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
}

.dropdown:hover .dropdown-content {
display: inline-table;
}

Answer

Ok, to get A in the right spot you have to put that ul element on the same level as other ul elements (B, C, D etc.) So change your list div like this

<div class="liste">
  <ul><li><a href="#">A</a></li></ul>
                        <div class="dropdown">

                    <div class="dropdown-content">
                        <li><a href="#">AA</a></li>
                        <li><a href="#">AB</a></li>
                        <li><a href="#">AC</a></li>
                        <li><a href="#">AD</a></li>
  </div>
  </div>

                    <ul>  <li><a href="#">B</a></li>    </ul>  

                    <ul>  <li><a href="#">c</a></li>    </ul>  
                    <ul>  <li><a href="#">d</a></li>    </ul>  
                    <ul>  <li><a href="#">e</a></li>    </ul>  
                    <ul>  <li><a href="#">f</a></li>    </ul>  
                    <ul>  <li><a href="#">g</a></li>    </ul>  
                    <ul>  <li><a href="#">h</a></li>    </ul>  
                    <ul>  <li><a href="#">i</a></li>    </ul>  
                    <ul>  <li><a href="#">j</a></li>    </ul>  
                    <ul>  <li><a href="#">k</a></li>    </ul>  
                    <ul>  <li><a href="#">l</a></li>    </ul>  
                    <ul>  <li><a href="#">m</a></li>    </ul>  
                    <ul>  <li><a href="#">n</a></li>    </ul>  
                    <ul>  <li><a href="#">o</a></li>    </ul>  
                    <ul>  <li><a href="#">p</a></li>    </ul>  
                    <ul>  <li><a href="#">q</a></li>    </ul>  
                    <ul>  <li><a href="#">r</a></li>    </ul>  
                    <ul>  <li><a href="#">s</a></li>    </ul>  
                    <ul>  <li><a href="#">t</a></li>    </ul>  
                    <ul>  <li><a href="#">u</a></li>    </ul>  
                    <ul>  <li><a href="#">v</a></li>    </ul>  
                    <ul>  <li><a href="#">w</a></li>    </ul>  
                    <ul>  <li><a href="#">y</a></li>    </ul>  
                    <ul>  <li><a href="#">z</a></li>    </ul>  
            </div>

Then find these properties and remove padding left:

.header .liste {
    background: #ffd564;
    border-bottom: 5px solid #ffecb8;
    font-size: 13px;
    height: 50px;
    overflow: hidden;
    /* padding-left: 25px; */
    margin-top: 30px;
}

Then move your opened dropdown down (top: 50px)and change min width to 948px

.dropdown-content {
    /* display: none; */
    position: absolute;
    background-color: #ffecb8;
    min-width: 948px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    padding: 12px 16px;
    top: 50px;
}

Then give your liste li padding left:

.liste li {
    padding-left: 25px;
}

And here is the screenshot of the result: http://screencast.com/t/RD3Akbot

Also, because structure changed you will have to deal with hover.

Here is the code for the hover:

.liste ul:hover + .dropdown {
    display: block;
}

This says, when you hover over this ul element show next .dropdown div. So all you have to do is add .dropdown sections underneath appropriate ul section. I will add the code snippet below.

<ul>  <li><a href="#">A</a></li>    </ul>
<div class="dropdown">
                    <div class="dropdown-content">
                        <li><a href="#">AA</a></li>
                        <li><a href="#">AB</a></li>
                        <li><a href="#">AC</a></li>
                        <li><a href="#">AD</a></li>
  </div>
  </div>
<ul>  <li><a href="#">B</a></li>    </ul>
<div class="dropdown">
                    <div class="dropdown-content">
                        <li><a href="#">AA777</a></li>
                        <li><a href="#">AB777</a></li>
                        <li><a href="#">AC777</a></li>
                        <li><a href="#">AD777</a></li>
  </div>
  </div>

Oh, I forgot you have to declare your .dropdown display:none too. So when you hover it will display block.

Comments