re1man
re1man

Reputation: 2367

Tabs stacking (on top each other)

I have a tabbed interface (with button like tabs), and my problem is that they stack on top each other:enter image description here

very rough sketch BTW. Here is the css for the tabs:

ul.tabs {
    margin: 0;
    padding: 0;
    float: left;
    list-style: none;
    height: 50px; /*--Set height of tabs--*/
    border-radius:2px;
    width: 100%;
}
ul.tabs li {
    float: left;
    margin: 0;
    padding: 0;
    height: 32px; /*--Subtract 1px from the height of the unordered list--*/
    line-height: 31px; /*--Vertically aligns the text within the tab--*/
    margin-bottom: -1px; /*--Pull the list item down 1px--*/
    overflow: hidden;
    position: relative;
    background: #FFFFFF;
    border-radius: 5px;
    margin-right:100px;
    opacity: .8;
}
ul.tabs li a {
    text-decoration: none;
    color: #000;
    display: inline;
    padding: 0 20px;
    border-radius: 5px;
    outline: none;
}
ul.tabs li a:hover {
    background: #ccc;
}
html ul.tabs li.active, html ul.tabs li.active a:hover  {
    border-radius: 5px;
    color: #000000;
}
.tab_container {
    border-radius: 5px;
    overflow: hidden;
    clear: both;
    float: left; width: 100%;
    background: #FFFFFF;
    opacity: .8;
    max-width:800px;
}

and the html:

<ul class="tabs">
            <li><a href="#tab4"><img src = "images/badge.png"></a></li>
            <li><a href="#tab1"><img src = "images/scroll.png"></a></li>
            <li><a href="#tab2"><img src = "images/friends.png"></a></li>
            <li><a href="#tab3"><img src = "images/compass.png"></a></li>
            <li><a href="#tab5"><img src = "images/profile.gif"></a></li>
        </ul>

Upvotes: 2

Views: 1295

Answers (3)

mshell_lauren
mshell_lauren

Reputation: 5236

At first it took me a while to understand what your problem was. So if I get it correctly, it looks like the code is fine, until you try and shrink the browser window - the the tabs line up on top of each other.

To solve this, I specified a max-width and, most importantly, a min-width for the ul element (you can also just specify a width, like width : 900px; ). I also made sure to stick the ul in a containing div, and specify that div in the css. The final css worked like this:

div.contain {
}

ul.tabs {
    margin: 0;
    padding: 0;
    float: left;
    list-style: none;
    height: 50px; /*--Set height of tabs--*/
    border-radius:2px;
    max-width:1000px;
    min-width: 900px;
}

And the html looked like:

<div class = "contain">
    <ul class="tabs">
        <li><a href="#">1</a></li>
        <li><a href="#">2</a></li>
        <li><a href="#">3</a></li>
        <li><a href="#">4</a></li>
        <li><a href="#">5</a></li>
    </ul>
</div>

Upvotes: 1

coder
coder

Reputation: 13248

Here is a sample to check out: http://jsfiddle.net/trAny/2/

$(function() {
  $("#tabs").tabs();
});
ul.tabs {
  margin: 0;
  padding: 0;
  float: left;
  list-style: none;
  height: 50px;
  /*--Set height of tabs--*/
  border-radius: 2px;
  width: 100%;
}

ul.tabs li {
  float: left;
  margin: 0;
  padding: 0;
  height: 32px;
  /*--Subtract 1px from the height of the unordered list--*/
  line-height: 31px;
  /*--Vertically aligns the text within the tab--*/
  margin-bottom: -1px;
  /*--Pull the list item down 1px--*/
  overflow: hidden;
  position: relative;
  background: #FFFFFF;
  border-radius: 5px;
  margin-right: 100px;
  opacity: .8;
}

ul.tabs li a {
  text-decoration: none;
  color: #000;
  display: inline;
  padding: 0 20px;
  border-radius: 5px;
  outline: none;
}

ul.tabs li a:hover {
  background: #ccc;
}

html ul.tabs li.active,
html ul.tabs li.active a:hover {
  border-radius: 5px;
  color: #000000;
}

.tab_container {
  border-radius: 5px;
  overflow: hidden;
  clear: both;
  float: left;
  width: 100%;
  background: #FFFFFF;
  opacity: .8;
  max-width: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="demo">

  <ul id="tabs">
    <ul>
      <li><a href="#tabs-1">tab1</a></li>
      <li><a href="#tabs-2">tab2</a></li>
      <li><a href="#tabs-3">tab3</a></li>
    </ul>
    <ul id="tabs-1">
      <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper
        leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum.
        Nunc tristique tempus lectus.</p>
    </ul>
    <ul id="tabs-2">
      <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean
        aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat.
        Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
    </ul>
    <ul id="tabs-3">
      <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia
        nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
      <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit,
        magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum
        rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
    </ul>
  </ul>

</ul>
<!-- End demo -->

Upvotes: 0

Hady Elsahar
Hady Elsahar

Reputation: 2151

i've tried this code on FIrefox , IE 7 8 9 , Chrome and it seems to work fine

maybe u put the in a container in fixed length which forces the

  • tabs to appear under each others , i tried to change this in the code to ellaborate what i mean

    the code is here : http://pastie.org/2790322 check the code if i miss understood something and this is a printscreen :

    snapshot

    Upvotes: 0

  • Related Questions