CSS 布局:2 列固定流体(再次)

发布于 2024-10-29 07:59:33 字数 1857 浏览 10 评论 0原文

我正在尝试设置一个 2 列布局,其中左侧区域是固定的,主要内容是流动的。我在这里看到了几个答案,它们往往有效。然而,当我在“左侧”区域使用“jsTree”并在主/内容区域使用 jQuery UI 选项卡时,会出现一些奇怪的行为。

html

<div id="main">
    <div id="left">
        <div id="tree">
        </div>
    </div>
    <div id="right">
        <ul>
            <li><a href="#a">A</a></li>
            <li><a href="#b">B</a></li>
            <li><a href="#c">C</a></li>
        </ul>
        <div id="a">
            <h3>A is here</h3>
        </div>
        <div id="b">
            <h3>B is here</h3>
        </div>
        <div id="c">
            <h3>C is here</h3>
        </div>
    </div>
</div>

css

#left {
    float: left;
    width: 200px;
    overflow: auto;
}

#right {
    margin: 0 0 0 200px;
}

javascript

$(document).ready(function() {
    $('#right').tabs();
    $('#tree').jstree({
        "plugins" : [ "json_data", "themes"],
        "json_data" : {
            "data" : [
                { 
                    "data" : "A node", 
                    "children" : [ "Child 1", "Child 2" ]
                },
                { 
                    "attr" : { "id" : "li.node.id" }, 
                    "data" : { 
                        "title" : "Long format demo", 
                        "attr" : { "href" : "#" } 
                    } 
                }
            ]
        }, 
    });
});

我遇到的问题是,当我展开树(左侧)时,右侧的选项卡开始变得奇怪。包含选项卡的区域(我认为是元素)垂直增长。

看一下这里的示例:http://jsfiddle.net/codecraig/gBUw2/

I'm trying to setup a 2-column layout where the left area is fixed and the main content is fluid. I've seen several answers on here, which tend to work. However, there is some odd behavior when I use a "jsTree" in my "left" area and jQuery UI tabs in the main/content area.

html

<div id="main">
    <div id="left">
        <div id="tree">
        </div>
    </div>
    <div id="right">
        <ul>
            <li><a href="#a">A</a></li>
            <li><a href="#b">B</a></li>
            <li><a href="#c">C</a></li>
        </ul>
        <div id="a">
            <h3>A is here</h3>
        </div>
        <div id="b">
            <h3>B is here</h3>
        </div>
        <div id="c">
            <h3>C is here</h3>
        </div>
    </div>
</div>

css

#left {
    float: left;
    width: 200px;
    overflow: auto;
}

#right {
    margin: 0 0 0 200px;
}

javascript

$(document).ready(function() {
    $('#right').tabs();
    $('#tree').jstree({
        "plugins" : [ "json_data", "themes"],
        "json_data" : {
            "data" : [
                { 
                    "data" : "A node", 
                    "children" : [ "Child 1", "Child 2" ]
                },
                { 
                    "attr" : { "id" : "li.node.id" }, 
                    "data" : { 
                        "title" : "Long format demo", 
                        "attr" : { "href" : "#" } 
                    } 
                }
            ]
        }, 
    });
});

The problem I'm having is, as I expand the tree (on the left) the tabs on the right start getting funky. The area containing the tabs (the element I believe) grows vertically.

Take a look here for this example: http://jsfiddle.net/codecraig/gBUw2/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野の 2024-11-05 07:59:33

约西亚说得对,但更好的解决方案是改变清晰修复技术的性质。 .ui-helper-clearfix 这样做:

.ui-helper-clearfix::after {
    clear: both;
    content: '.';
    display: block;
    height: 0px;
    visibility: hidden;
}

问题是 clear:both。您可以通过以下方式获得所需的清除,而不会丢失全角块显示:

#right .ui-helper-clearfix {
    clear: none;
    overflow: hidden;
}

clear:both clear-fix 替换为 overflow:hidden代码> 清除修复

Josiah has it right but a better solution is to change the nature of the clear-fix technique. The .ui-helper-clearfix does this:

.ui-helper-clearfix::after {
    clear: both;
    content: '.';
    display: block;
    height: 0px;
    visibility: hidden;
}

And the problem is the clear:both. You can get the desired clearing without losing the full-width block display with this:

#right .ui-helper-clearfix {
    clear: none;
    overflow: hidden;
}

That replaces the clear:both clear-fix with an overflow:hidden clear-fix.

http://jsfiddle.net/ambiguous/BkWWW/

扛起拖把扫天下 2024-11-05 07:59:33

小部件选项卡标题有一个明确的修复。 更新了小提琴。您可以使用非浮动布局来修复此问题,或者像这样覆盖 css:

#right .ui-helper-clearfix { display: inline-block; }

这使得标头不会扩展容器的整个宽度。

The widget tabs header has a clear fix. updated fiddle. You could fix this with a non float layout, or override the css like so:

#right .ui-helper-clearfix { display: inline-block; }

This makes it so that the header does not expand the full width of the container however.

〆一缕阳光ご 2024-11-05 07:59:33

您需要做的就是简单地调整您的 css,如下所示:

#left {
    float: left;
    width: 23%;
    overflow: auto;
}

#right {
    float: left;
    width: 75%;
    display: block;
}

这也可以解决选项卡容器不扩展整个宽度的问题。尽管您可以将 #right 的宽度百分比调整为您喜欢的任何值。

All you need to do is to simply tweak your css, like this:

#left {
    float: left;
    width: 23%;
    overflow: auto;
}

#right {
    float: left;
    width: 75%;
    display: block;
}

This would also fix the issue that the tabs' container don't expand full width. Though you could tune the width percentage of #right to whatever you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文