gpt4 book ai didi

html - 当一个元素被转换隐藏时,如何让 flex child 展开?

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:29 26 4
gpt4 key购买 nike

我目前正在尝试学习如何使用 display: flexbox 并且我正在尝试在涉及主要内容和使用 transform< 隐藏的边栏的元素中使用它 属性。

但是,如果侧边栏被转换隐藏,则主要内容不会在父级内扩展到全宽。如何强制主要内容全宽显示?

.parent {
background-color: blue;
display: flex;
}

.child {
background-color: red;
flex: 1 1;
}

.hidden-child {
background-color: green;
transform: translateX(100px);
width: 100px;
}

JSFiddle:https://jsfiddle.net/Crotanite/d2vwhnk5/

最佳答案

使用flex-basis强制主要内容占宽度的 100%。
您还可以使用 white-space: nowrap 来防止子项分成多行。

body {
margin: 0;
overflow: hidden;
}

.parent {
background-color: blue;
display: flex;
align-items: flex-start;
}

.child {
background-color: red;
flex: 1 0 100%; /* here */
}

.hidden-child {
background-color: green;
transform: translateX(100px);
width: 100px;
white-space: nowrap; /* and here */
}
<div class="parent">
<div class="child">
child
</div>
<div class="hidden-child">
hidden child
</div>
</div>

关于html - 当一个元素被转换隐藏时,如何让 flex child 展开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56620589/

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