gpt4 book ai didi

css - 如何防止右 div 包裹在左 div 下?

转载 作者:行者123 更新时间:2023-11-28 12:14:51 25 4
gpt4 key购买 nike

see fiddle here

当我从右到左逐渐调整窗口大小时:

  • 红色右边的框越来越小了……ok
  • 第二个绿色元素在第一个绿色元素下面......好的
  • 红色右侧框和 2 个内部绿色元素位于蓝色左侧框下方...不行

我希望右侧的红色框保持不变,其余行为不变。

尝试了很多东西,比如 block: inline-blockmin-widthwhite-space: nowrap,都没有用。

请帮忙!

(谁能解释为什么右侧还有那么多空间时红框会换行?)

谢谢!!!

最佳答案

display: table 用于父级,display: table-cell; 用于子级,这就是您所追求的。

Have a fiddle!

  1. 移除 .left.right 上的 float (将 float 留在绿色框上)
  2. display:table添加到.wrapper
  3. display: table-cell; 添加到您的 .left.right
  4. vertical-align:top; 添加到您的“表格单元格”,这样内容就不会垂直居中

CSS

html {
width:100%;
height:100%;
}
body {
padding: 0px;
margin: 0px;
width:100%;
height:100%;
}
.wrapper {
width: 100%;
height:100%;
display: table;
}
.left {
width: 25%;
min-width:100px;
height: 100%;
margin:0px;
border: 1px solid blue;
display: table-cell;
vertical-align:top;
}
.right {
display: table-cell;
vertical-align:top;
width: 70%;
height: 100%;
border: 1px solid red;
}
.item {
width:100px;
height:100px;
margin:20px;
float: left;
border:1px solid green;
}

关于css - 如何防止右 div 包裹在左 div 下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610446/

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