gpt4 book ai didi

css - 调整 FlexBox 容器的大小

转载 作者:技术小花猫 更新时间:2023-10-29 11:23:08 26 4
gpt4 key购买 nike

我正在尝试使用 flexbox 模型创建一个始终延伸到屏幕边界的多列布局。这完全符合我的意愿。但是,我也希望能够水平调整一列或多列的大小。我试过使用 jQuery UI 来调整大小,但不出所料,这并不能正常工作

如下面的演示所示,当您开始调整列大小时,它会“跳跃”大约 100 像素。

jsFiddle example

任何人都可以为此提供解决方案,或者提供另一种动态调整 flexbox 容器大小的方法吗?所有代码也粘贴在下面。

HTML:

<div id="container">
<div id="box1" class="widget-container">
<div class="widget">
<div class="widget-content">
Item 1
</div>
</div>
<div class="widget">
<div class="widget-content">
Item 2
</div>
</div>
</div>
<div id="box2" class="widget-container">
<div class="widget">
<div class="widget-content">
Item 3
</div>
</div>
</div>
<div id="box3" class="widget-container">
<div class="widget">
<div class="widget-content">
Item 4
</div>
</div>
<div class="widget">
<div class="widget-content">
Item 5
</div>
</div>
</div>
</div>

CSS:

html, body {
height: 100%;
margin: 0;
}
body {
position: absolute;
height: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
padding: 0;
margin: 5px 5px 5px 5px;
}
#container {
height: 100%;
width: 100%;
background-color: #FFFFFF;
border-radius: 5px 5px 0 0;
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
-webkit-box-pack: justify;
-moz-box-pack: justify;
box-pack: justify;
-webkit-box-align: stretch;
-moz-box-align: stretch;
box-align: stretch;
}
#box1, #box2, #box3 {
margin: 5px;
padding: 2px;
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
box-orient: vertical;
-webkit-box-pack: start;
-moz-box-pack: start;
box-pack: start;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
}
div.widget
{
padding: 2px;
-moz-border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
margin-bottom: 10px;
background-color: #999999;
}
div.widget-maximised {
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
box-orient: vertical;
-webkit-box-pack: start;
-moz-box-pack: start;
box-pack: start;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
}
div.widget div.widget-content
{
background-color: #FFF;
color: #333;
line-height: 1.2em;
overflow: auto;
padding: 5px;
margin: 5px;
width: auto;
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
}

JS:

$("#box1, #box2, #box3").resizable({
handle: "e",
cancel: "cancel"
});

最佳答案

你的问题是你依赖于 2009 年过时的 Flexbox 规范中的属性。如果你添加现代属性,它会像你预期的那样顺利工作。

http://jsfiddle.net/GdPRS/2/

/* line 6, ../sass/test.scss */
html, body {
height: 100%;
margin: 0;
}

/* line 10, ../sass/test.scss */
body {
position: absolute;
height: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
padding: 0;
margin: 5px 5px 5px 5px;
}

/* line 20, ../sass/test.scss */
#container {
height: 100%;
width: 100%;
background-color: #FFFFFF;
border-radius: 5px 5px 0 0;
display: -webkit-box;
display: -moz-box;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}

/* line 29, ../sass/test.scss */
#box1, #box2, #box3 {
margin: 5px;
padding: 2px;
display: -webkit-box;
display: -moz-box;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1;
-ms-flex: 1 1;
flex: 1 1;
}

/* line 37, ../sass/test.scss */
div.widget {
padding: 2px;
-moz-border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
margin-bottom: 10px;
background-color: #999999;
}

/* line 44, ../sass/test.scss */
div.widget-maximised {
display: -webkit-box;
display: -moz-box;
display: -webkit-flexbox;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-box-direction: normal;
-moz-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1;
-ms-flex: 1 1;
flex: 1 1;
}

/* line 51, ../sass/test.scss */
div.widget div.widget-content {
background-color: #FFF;
color: #333;
line-height: 1.2em;
overflow: auto;
padding: 5px;
margin: 5px;
width: auto;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1 1;
-ms-flex: 1 1;
flex: 1 1;
}

关于css - 调整 FlexBox 容器的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15944178/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com