繁体   English   中英

如何在 flexbox 中的内容旁边放置一旁?

[英]How to make aside next to content in flexbox?

我是 web 开发的新手,我第二次尝试使用 flexbox,因为我在为网站做布局时遇到了浮动问题。 基本上,我想放在内容旁边,但试图浮动它,它就消失了。 (所有颜色仅用于识别不同的元素)。

这是我的布局想法的图像:

在此处输入图像描述

 *, *::after, *::before { box-sizing: border-box; } body { margin: 0; } header { display: flex; justify-content: center; align-items: center; max-width: 135em; height: 7em; background: rgb(68, 100, 155); } section { display: flex; justify-content: center; flex-direction: column; align-items: center; background: chocolate; max-width: 100em; height: 50em; } aside { display: block; background: chartreuse; float: right; max-width: 20em; height: 50em; } footer { display: flex; justify-content: center; align-items: center; background: crimson; max-width: 135em; height: 22em; }
 <header></header> <section></section> <aside></aside> <footer></footer>

您需要将代码包装在div中并将其设置为display: flex; 像这样:

<header></header>
<div class="flex-container">
  <section></section>
  <aside></aside>
</div>
<footer></footer>

然后在您的 CSS 中:

.flex-container {
  display: flex;
}

.flex-container section {
  flex: 1; // By your image example it looks like you want this element to stretch
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM