0

I have a 3 tabbed menu, each one displays it's own content within the same page.

I was having a problem using overflow"hidden until someone on here pointed out that to use this, I needed to set a height on the div.

That works fine.

However as the content under each tab is different lengths a set height is no good to me, instead the height needs to be dynamic.

I tried setting height to 100% and no luck (as you will see here, back to the original problem of the content not displaying at all) http://jsfiddle.net/UcqfA/7/

I also tried setting min-height to 945px (this being the lowest height needed out of the 3 tabs) but this just seems to ignore the minimum and remain at a static height of 945 px regardless of which tab's content I am viewing.

Could anyone advise how I can make the div dynamic so the height always adapts to the content?

Code used in JSFIDDLE above

<div class="cont-wrapper">
<ul class="tabs">
    <li>
      <input type="radio" checked name="tabs" id="tab1">
      <label for="tab1">tab 1</label>
      <div id="tab-content1" class="tab-content animated fadeIn">
CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
      </div>
    </li>
    <li>
      <input type="radio" name="tabs" id="tab2">
      <label for="tab2">tab 2</label>
      <div id="tab-content2" class="tab-content animated fadeIn">
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE v CONTENT GOES HERE CONTENT GOES HERE
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
      </div>
    </li>
    <li>
      <input type="radio" name="tabs" id="tab3">
      <label for="tab3">tab 3</label>
      <div id="tab-content3" class="tab-content animated fadeIn">
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE v CONTENT GOES HERE CONTENT GOES HERE 
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
        CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE CONTENT GOES HERE 
      </div>
    </li>
</ul>

.tabs input[type=radio] {
      position: absolute;
      top: -9999px;
      left: -9999px;
}
.tabs {
width: 980px;
float: none;
list-style: none;
position: relative;
padding: 0;
margin: 20px auto;
}
  .tabs li{
    float: left;
  }
.tabs label {
      display: block;
      padding: 10px 20px;
      border-radius: 2px 2px 0 0;
      color: #08C;
      background: rgba(255,255,255,0.2);
      cursor: pointer;
      position: relative;
      top: 3px;
      -webkit-transition: all 0.2s ease-in-out;
      -moz-transition: all 0.2s ease-in-out;
      -o-transition: all 0.2s ease-in-out;
      transition: all 0.2s ease-in-out;
  }
  .tabs label:hover {
    background: rgba(255,255,255);
    top: 0;
  }

  [id^=tab]:checked + label {
    background: #08C;
    color: white;
    top: 0;
  }

  [id^=tab]:checked ~ [id^=tab-content] {
      display: block;
  }
  .tab-content{
    display: none;
    text-align: left;
    width: 100%;
    font-size: 20px;
    line-height: 140%;
    padding-top: 10px;
    background: #08C;
    padding: 15px;
    color: #4a4949;
    position: absolute;
    top: 53px;
    left: 0;
    box-sizing: border-box;
    -webkit-animation-duration: 0.5s;
    -o-animation-duration: 0.5s;
    -moz-animation-duration: 0.5s;
    animation-duration: 0.5s;
  }
  .cont-wrapper{
    width: 980px;
    background: #82cff5;
    padding-right: 20px;
    padding-left: 20px;
overflow:hidden;
height:100%;
  }
jfar_2020
  • 161
  • 4
  • 23
  • CSS is so messy. I wish we could use XAML instead of CSS. – uSeRnAmEhAhAhAhAhA Feb 04 '14 at 12:11
  • Instead of coding everything, why do not you just use jquery ui tabs ? Fiddle example: http://jsfiddle.net/franchez/8ENLM/6/ Also please note li is a tag defining a list item. It's not a good idea to insert some div and label tags inside. – franchez Feb 04 '14 at 12:22
  • @user247245 it's a site initially developed my another company and currently doctype is simply ' ' – jfar_2020 Feb 04 '14 at 12:31
  • @franchez I could try that but I would not still have the same issue? – jfar_2020 Feb 04 '14 at 12:31
  • Did you check my fiddle example ? I think it will do the job, it's already resizing automatically. – franchez Feb 04 '14 at 12:36
  • Sorry, yes I can see the fiddle works but in practice on the site adding your code doesn't seem to have any effect? – jfar_2020 Feb 04 '14 at 12:38

1 Answers1

1

You missed to set the height of cont-wrappers parent class, add this in you css :

demo

html,body{
    height:100%;
    width:100%;
    margin:0;
    padding:0;
}
NoobEditor
  • 15,563
  • 19
  • 81
  • 112
  • Doesn't work for me, my code here is just a selection from a lot on the page. When I add the above to my body tag, no difference. Without copying and pasting ALL of it, the main container all of this sits in is cont-wrapper then that sits in body so like you say, simply adding that to body should work. I do also have divs inside cont-wrapper but guessing that isn't relevant? – jfar_2020 Feb 04 '14 at 12:29
  • make sure that u have mentioned `height` and `width` in all the `div`...then it would definately work!! – NoobEditor Feb 04 '14 at 14:06