spwin
spwin

Reputation: 61

CSS + HTML dropdown menu overlapping issue

I have a problem with dropdown menu children overlapping parent element. Please check my fiddle to understand the problem: Fiddle example

HTML code:

<div id="main_category_menu">
<ul id="menu">
        <li>
            <a href="#">Category</a>
            <div class="menu-container">
            <h3>Text goes here</h3>
            Items count: tralala<hr/>
            <ul class="menu_category">
                <li class="menu_subcategory">
                    <a href="browse.php?id=76">
                        Advertising(0)
                    </a>
                </li>
                <li class="menu_subcategory">
                    <a href="browse.php?id=76">
                        Blalala(0)
                    </a>
                </li>
                <li class="menu_subcategory">
                    <a href="browse.php?id=76">
                        Super megatron(0)
                    </a>
                </li>
            </ul>
            </div>
        </li>
</ul>
</div>

CSS code:

#main_category_menu{
width: 100%;
}

#menu ul, #menu li {
  line-height:22px;
  text-align:left;
  font-size:14px;
}

#menu {
  list-style:none;
  width:100%;
  margin:0 auto;
  height:45px;
  padding:5px 30px;
}

#menu li {
  float:left;
  display:block;
  position:relative;
  text-align:center;
  padding:4px 10px;
  margin:7px 30px 0 0;
  border:none;
}
#menu li:hover {
  border:1px solid #b7b7b7;
  border-bottom: none;
  padding:4px 9px;
  background: yellow;
      border-radius:5px 5px 0 0;
  -moz-border-radius:5px 5px 0 0;
  -webkit-border-radius:5px 5px 0 0;
  z-index: 10;
}
#menu li a {
  font-size:14px;
  color: #444444;
  display:block;
  outline:0;
  text-decoration:none;
}
#menu li:hover a {
  color:#161616;
}

#menu .menu-container{
  margin:0px auto;
  float:left;
  position:absolute;
  left:-999em;
  text-align:left;
  padding:10px 5px;
  border:1px solid #b7b7b7;
  background-color: #ffffff;

      border-radius:0 5px 5px 5px;
  -moz-border-radius:0 5px 5px 5px;
  -webkit-border-radius:0 5px 5px 5px;
}
#menu .menu-container {
  width:280px;
  background: transparent url('logo.gif') no-repeat right bottom;
}
#menu li:hover .menu-container{
  top:auto;
  left:-1px;
}

#menu p, #menu h2, #menu h3, #menu ul li {
  line-height:21px;
  font-size:12px;
  text-align:left;
}
#menu p {
  line-height:18px;
  margin-bottom:10px;
  color:#F2E8E8;
}
#menu h3, #menu h2 {
  font-size:11px;
  margin:7px 0 14px 0;
  padding-bottom:5px;
  text-transform:uppercase;
  color: #999999;
}
#menu li:hover div a {
  color: #666666;
  font-size: 11px;
  padding-left: 6px;
}
#menu li:hover div a:hover {
  color: #FAFAFA;
  background:#99DE00;
}
#menu li ul {
  list-style:none;
  padding:0;
  margin-bottom:12px;
}  
#menu li ul li {
  float: none;
  font-size: 12px;
  line-height: 24px;
  margin: 0;
  padding: 0;
  position: relative;
  text-align: left;
  width: 100%;
}
#menu li ul li:hover {
  background: none;
  border: medium none;
  margin: 0;
  padding: 0;
}

I need this to be like: Result image example

Tried to adding z-index; but it doesn't work for my. Any suggestion would be appriciated. Thanks! :)

Upvotes: 6

Views: 25731

Answers (4)

jsea
jsea

Reputation: 4037

The issue is with stack(ing) order.

Since li contains .menu-container and li has a stacking context already, .menu-container creates a sub-context within it and can never be shown below it. What you need to do is take li out of stacking order, and then give .menu-container a negative z-index for it show up below it. However, if no ancestor of li is in a stacking context, your .menu-container may show up below the page content. Thus, you should probably have a parent of li have a z-index and accompanying position to put it in stacking order.

I am not sure if this works correctly on IE6/IE7 or not.

Here is a forked JSFiddle showing the changes. (li no longer has a z-index and .menu-container now has a negative z-index; also the parent ul#menu is now put into stacking order so that .menu-container does not show up below page content)

Upvotes: 3

Ram
Ram

Reputation: 57

Something like partial border using before or after will help you check this fiddle

   #menu .menu-container:before{
    content: '';
width: 222px;
margin-left: 64px;
height: 1px;
background: #b7b7b7;
position: absolute;
top: -0.5px;
}

http://jsfiddle.net/ncqke/9/

Upvotes: 0

dfsq
dfsq

Reputation: 193261

You can achieve this by using :after pseudo element like this:

#menu > li:hover:after {
    content: '';
    background: yellow;
    position: absolute;
    top: 100%;
    width: 100%;
    height: 4px;
    left: 0;
    margin-top: -4px;
    z-index: 2;
}

Instead of :after you can use additional element like span of div, that you can add to markup.

http://jsfiddle.net/ncqke/7/

Upvotes: 3

Riskbreaker
Riskbreaker

Reputation: 4791

Whats the need of the background?:

background: transparent url('logo.gif') no-repeat right bottom;

FIDDLE

Upvotes: 0

Related Questions