jQuery tabs: panel covers tabs at 100% height

后端 未结 10 874
生来不讨喜
生来不讨喜 2021-01-11 13:15

I\'m trying to use the tabs widgets of jQuery-UI having panels content to extend to the whole available space.

Here\'s a simplified version of what I\'ve got so far:

相关标签:
10条回答
  • 2021-01-11 13:39

    Is this what you're after?

    http://jsfiddle.net/MhEEH/5/

    html, body {
        height: 100%;   
    }
    #tabs {
        position: absolute;
        top: 0;
        bottom:0;
        left: 0;
        right: 0;
    }
    #tab-1 {
        background: green;
        height: 100%;
    }
    
    0 讨论(0)
  • 2021-01-11 13:40

    Instead of using your own CSS, use jQuery UI's built-in feature.

    var tabs = $("#tabs").tabs({heightStyle: "fill"});
    

    From the API documentation:

    heightStyle

    Type: String

    Default: "content"

    Controls the height of the tabs widget and each panel. Possible values:

    • "auto": All panels will be set to the height of the tallest panel.
    • "fill": Expand to the available height based on the tabs' parent height.
    • "content": Each panel will be only as tall as its content.

    Although you are right that a plain CSS solution would be very nice, since you are using JavaScript anyway to build the tab functionality, it will be best to use the existing capabilities of the script you already have.


    UPDATE:

    • See http://jsfiddle.net/MhEEH/45/ for the simplest full example. Note that it does not need any CSS position rules.

    • You need to use http://benalman.com/projects/jquery-resize-plugin/ (or similar) to watch the parent for size changes. Browsers only fire the resize event on the window itself by default, but this plugin extends support for that event to arbitrary elements being resized.

    0 讨论(0)
  • 2021-01-11 13:42

    Below is a link to my CSS solution hopefully that works for you

    http://jsfiddle.net/MhEEH/17/

    html, body {
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
    #tab-list {
        position: absolute;
        z-index: 10;
        top: 0;
        left: 0;
        width: 100%;
    }
    #tabs {
        position: absolute;
        top: 0;
        bottom:0;
        left: 0;
        right: 0;
    }
    #tab-1, #tab-2 {
        background: green;
        position: absolute;
        top: 48px;
        bottom: 0;
        left: 0;
        right: 0;
        padding-top: 10px;
    }
    

    Someone has mentioned the Coda slider which is a great solution as well and as an alternative I might suggest this elastic content slider from codrops

    http://tympanus.net/codrops/2013/02/26/elastic-content-slider/

    Hope it helps,

    Cheers

    0 讨论(0)
  • 2021-01-11 13:48

    I just tried to use this:

    #tab-1 {
        background: green;
        position: relative;
        height:100%;
    }
    

    and in jsfiddle it works fine. not sure how it will be on your page http://jsfiddle.net/MhEEH/7/

    0 讨论(0)
  • 2021-01-11 13:50

    The simplest Solution, two changes in CSS, and problem solved, #tabs{height:100%;}

    and #tab-1{top:45px;}

    this will do :) updated fiddle

    0 讨论(0)
  • 2021-01-11 13:52

    I don't see a need in using javascript here for basic style modifications. I've recently converted a single page full screen style app from doing all it's re sizing from javascript to pure CSS using positioning and stuff.

    Now onto a solution - try this.

    http://jsfiddle.net/MhEEH/16/

    #tab-1 {
        background: green;
        height: 100%;
    }
    

    I don't see a need in using absolute positioning on the green box element because the parent fills up the space, all you need to now do is height: 100% and it should fill up the rest of the space.

    Edit

    There seems to be an issue with the content not scrolling in this version. Struggling to find a fix for this. I feel like the jQuery UI is adding a bunch of styles and stuff to the #tab-1 div which might be causing your problem. Could be worth trying to reset the styles for #tab-1 and seeing what that leaves you with.

    0 讨论(0)
提交回复
热议问题