gpt4 book ai didi

html - 3 列 Flex 布局 - 中间列的宽度与其内容相同

转载 作者:行者123 更新时间:2023-12-02 04:10:42 25 4
gpt4 key购买 nike

到目前为止我的 fiddle :

.fill-height-or-more {
min-height: 100%;
display: flex;
}
.fill-height-or-more > div {
-webkit-box-flex: 1;
-webkit-flex: 1;
-moz-box-flex: 1;
-ms-flex: 1;
flex: 1;
display: flex;
justify-content: center;
flex-direction: column;
align-items : center;
}

.some-area > div {
padding: 1rem;
}
.some-area > div:nth-child(1) {
background: #88cc66;
}
.some-area > div:nth-child(2) {
background: #79b5d2;
}
.some-area > div:nth-child(3) {
background: #8cbfd9;
}
.some-area > div h1, .some-area > div h2 {
margin: 0 0 0.2rem 0;
}
.some-area > div p {
margin: 0;
}

html, body {
height: 100%;
}
<section class="some-area fill-height-or-more">
<div>
<h1>LEFT</h1>

</div>
<div>
<h2>Two</h2>
<p>This Column should</p>
<p>only be as width as</p>
<p>its content.</p>
</div>
<div>
<h2>RIGHT</h2>
</div>
</section>

这篇文章是我的 previous post 的续集.

任务 1:我希望中间列的宽度与其内容相同。然后,左右列应相等地填充其余空间,以便中间列始终保持在中间。

提前感谢您一小时的帮助!

莫夫

最佳答案

您只需将 flex: 1 添加到 leftright div 或根据您的情况 DEMO

.content {
display: flex;
height: 100vh;
}
.content > div {
display: flex;
align-items: center;
justify-content: center;
}
.left,
.right {
flex: 1;
background: lightblue;
}
.middle {
background: lightgreen;
}
<div class="content">
<div class="left">Lorem</div>
<div class="middle">Lorem ipsum dolor sit amet.</div>
<div class="right">lorem</div>
</div>

关于html - 3 列 Flex 布局 - 中间列的宽度与其内容相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36889902/

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