-1

I have tabs which contain text. When I try to set the height with height:auto or height:100%, it works only when using px. However this prevents the tabs from expanding when the text is long.

this is my css:

.tab-section {
    float: left;
    width: 100%;
    height: 792px;
    margin-bottom: 25px;
} 

How do I make the height auto?

SURTLER77
  • 87
  • 1
  • 16

2 Answers2

0

It's because you are displaying the tab-content inside the li element. As the li it's a menu it looks like a broken layout.

You should display the tab-content outside of the tab-section. Also be aware of floating(for example, if the parent it has float: left, the child should also have float:left to fulfill the parent height)

Tiberiu Popescu
  • 4,486
  • 2
  • 26
  • 38
0

.tab-content with position:absolute

Based on feeela answer

absolute positioned elements are removed from the flow, thus ignored by other elements. So you can't set the parents height according to an absolutely positioned element.

You can use this script to handle it:

$("[type = radio]").click(function () {
    var oh=$(this).parent().find(".content").outerHeight();    
    $(".tabs").height(oh);
});

Fiddle demo

Also you can use viewport units(vh) or calc() on ul.tabs (css3)

Community
  • 1
  • 1
Hamix
  • 1,323
  • 7
  • 18