tags:

views:

68

answers:

3

How to overlap selected tab over 2nd level tab using css only?

This is HTML code

<div class="tabcontainer" id="tabcontainer">
    <ul id="tabitemscontainer1">
          <li class="selected"><a href="#">item 1</a>
             <ul class="level2">
                <li><a href="#">sub item 1 </a></li>
                <li> <a href="#">subitem 2</a></li>
             </ul>
          </li>
          <li><a href="#">item2</a></li>
      </ul>
</div>

I wrote this CSS

#tabcontainer {
height:62px;
position:relative;}

#tabitemscontainer1 > li {
-moz-border-radius:7px 7px 0 0;
background:none repeat scroll 0 0 #F0F7C1;
border-color:#EABF4A;
border-style:solid;
border-width:1px 1px 0;
float:left;
margin-right:2px;
padding:5px 10px 10px;}

#tabcontainer ul li li.selected a, #tabitemscontainer1 > li.selected > a {
color:#AE4329;
font-weight:bold;}

ul.level2 {
background:none repeat scroll 0 0 #F3F8C6;
border:1px solid #EABF4A;
left:0;
padding:6px;
position:absolute;
top:26px;
width:463px;}

#tabcontainer ul li li {
float:left;
padding:0 15px 0 4px;}

and get almost OK

I added example here : http://jsbin.com/owana4

alt text

But i need to achieve this conditions too . Selected tab should overlap on second level tap.

How to make this possible without using image or JavaScript?

alt text

A: 

Try a negative margin-left on item 2 and giving item 1 a higher z-index then the other tabs.

Tahbaza
but I'm not using z-index on any item. in screenshot "item 1" is selected.
metal-gear-solid
+1  A: 

Try pulling ul.level2 up 1 pixel with a negative margin, and changing the color of the bottom border on the selected level 1 tab to the background color.

li.selected { border-bottom-color: #F3F8C6; border-bottom-width: 1px; } ul.level2 { margin-top: -1px; }

If that ends up not working, you may need to adjust z-indexes or add some padding to the bottom to one of those elements. (Padding because two margins that butt up against each other will be treated as one margin with a value equal to the larger one).

Note that instead of border-bottom-width, you could just change the border-width value in your existing CSS.

Ryan Kinal
thx for answer but it's not working and where to add z-index?
metal-gear-solid
A: 
  1. The code, in the question above, has class="tabitemscontainer1" but the CSS has #tabitemscontainer1 instead.

    Change all the CSS selectors to .tabitemscontainer1.

  2. Next since ul.level2 is positioned absolutely, add: z-index: -1; to its CSS.

  3. Add:

    .tabitemscontainer1 > li.selected
    {
      border-bottom: none;
    }
    
  4. Change .tabitemscontainer1 > li to:

    .tabitemscontainer1 > li
    {
      -moz-border-radius:   7px 7px 0 0;
      background:           none repeat scroll 0 0 #F0F7C1;
      float:                left;
      margin-right:         2px;
      padding:              5px 10px 10px;
      border:               1px solid #EABF4A;
    }
    
  5. Adjust the top in ul.level2s CSS to line up the borders.

Brock Adams
if i add `z-index: -1` to `ul.level2` it's not showing at all
metal-gear-solid
Well that's the drawback of posting incomplete code. Based on the Q's code it should work (and does in my test). Please link to the page. Or at least pastebin a full snapshot of it.
Brock Adams
@Brock Adams - i made an example here http://jsbin.com/owana4
metal-gear-solid
@metal-gear-solid: when I browse that example and set `z-level: -1;` using Firebug, it acts just like it should and doesn't disappear.What happens when you view: http://jsbin.com/upeka4 ?
Brock Adams
it's fine now http://jsbin.com/upeka4 now how get this condition http://shup.com/Shup/374241/110619313-My-Desktop.png
metal-gear-solid
@metal-gear-solid: You mean with one of the submenu items (class="level2") selected? You would add the class "selected" to whichever `<li>` it was and then add a style for `#tabcontainer ul.level2 li.selected a`. See: http://jsbin.com/upeka4/4
Brock Adams
@Brock Adams - Thanks, now i got that result. Great help from your side. Thanks very much
metal-gear-solid
@metal-gear-solid: You're welcome. Glad to help.
Brock Adams
@Brock Adams - I found today. the 2nd level links are not working.
metal-gear-solid