JQuery UI tip: floated divs inside JQueryUI tabs

There’s a somewhat confusing problem that can happen if you want to use a multi column (floated div) chunk of content for a tab in JQuery UI tabs.

Basically, the floats inside the tab container cause the tab container to lose it’s height, making your content appear outside of the tab box.

Let us assume our code looks something like this:

The problem is that the floats inside the tab container cause the tab container height to be incorrect (Shown via Firefox)

The solution to this, was to apparently make the tab container float as well, by adding a float:left; width: 100%; to the ‘myTabs‘ div; making the content all appear correct.

End result css:

12 thoughts on “JQuery UI tip: floated divs inside JQueryUI tabs

  1. This issue has bugged me for so long. Thanks so much for posting this bit of info!! You have contributed well.

    Have you used jQuery UI tabs as form steps? If so, do you have any useful tips for that? I'd like to make (tab 2) default selected or disabled w/o the need for doing so with the jQuery code. Maybe by means of a class name and an extended function to the UI tabs initialization.

  2. You would call one of the methods for the JQuery tabs instance;

    To select another tab (0-based index):

    As shown above, I call select -after- the instance instantiation; it also has to be called after Dom is ready.

    To disable tab/tabs you'd do something like:

    $(“#tabs”).tabs(“option”, “disabled”, [0,2,3]);

    Where 0,2,3 are indexes of the tabs.

    Nitty-gritty details on the methods can be found on the bottom here:

    http://jqueryui.com/demos/tabs/#methods

  3. I'm glad I found this post. It was driving me crazy.

    I saw a question about this on Stackoverflow and no one had answered it. (The asker doesn't seem to interested in marking answers to any of his questions). You might post a link there back to this post for others with the same problem.

    Thanks again for posting this.

  4. I had to put float:left; width:100%; in both the #tab and .ui-tabs .ui-tabs-panel for it to float the items properly. Thanks for the tip!

  5. Just wondering: what was your thought process in figuring out this fix? I started to realize that it must have to do with float, but I don’t think it would have occurred to me to make the tab itself float left. Was that just a moment of inspiration for you, and you got lucky, or did it make sense somehow?

Leave a Reply

Your email address will not be published. Required fields are marked *