gpt4 book ai didi

html - 使用 Flexbox 使盒子并排 CSS

转载 作者:行者123 更新时间:2023-11-28 00:03:41 24 4
gpt4 key购买 nike

我正在努力使 explanationparticipation 类是 flexboxes,但彼此并排。而在它们下方,benefitsrequirements 将相互堆叠。

我尝试使用flex-direction:row;作为explanationparticipation部分,然后切换到flex- direction: column; 对于其余部分,但这不起作用。我需要帮助来弄清楚这是可以做到的。另外,我无法更改我的 HTML。

.main {
display: flex;
}

.benefits {
flex-direction: column;
}

.requirements {
flex-direction: column;
}
<main class="main" id="zen-supporting" role="main">
<section class="explanation" id="zen-explanation" role="article">
<h3>What's This About?</h3>
<p>There</p>
</section>

<section class="participation" id="zen-participation" role="article">
<h3>Participation</h3>
<p>Download</p>
</section>

<section class="benefits" id="zen-benefits" role="article">
<h3>Benefits</h3>
<p>Why participate?</p>
</section>

<section class="requirements" id="zen-requirements" role="article">
<h3>Requirements</h3>
<p>gtgtgtg</p>
</section>

最佳答案

您可以使用 wrapping flexbox 并使用 flex-basis 来调整布局 - 请参见下面的演示:

main{
display: flex;
flex-wrap: wrap; /* wrapping flexbox */
/* flex-direction is row by default - so not specified */
}

.explanation, .participation{
flex-basis: 50%; /* occupy half a row (flex line) */
}

.benefits, .requirements{
flex-basis: 100%; /* occupy the whole row (flex line) */
}

main > section { /* styling for illustration */
border: 1px solid;
box-sizing: border-box;
}
<main class="main" id="zen-supporting" role="main">
<section class="explanation" id="zen-explanation" role="article">
<h3>What's This About?</h3>
<p>There</p>
</section>

<section class="participation" id="zen-participation" role="article">
<h3>Participation</h3>
<p>Download</p>
</section>

<section class="benefits" id="zen-benefits" role="article">
<h3>Benefits</h3>
<p>Why participate?</p>
</section>

<section class="requirements" id="zen-requirements" role="article">
<h3>Requirements</h3>
<p>gtgtgtg</p>
</section>
</main>

关于html - 使用 Flexbox 使盒子并排 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55840007/

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