【发布时间】:2021-06-16 02:22:11
【问题描述】:
我一直在练习 html 和 CSS,并试图复制这个网站: https://codepen.io/freeCodeCamp/full/VPaoNP
但是,我对 flexbox 有点卡住,并且对为什么我的 h1、h2 和“调查表单”类在我设置 display: flex 时突然变成内联元素感到困惑。
html {
box-sizing: border-box;
}
body {
background-color: #bdb2ff;
display: flex;
}
.survey-form {
background-color: #a0c4ff;
}
<h1>freeCodeCamp Survey Form</h1>
<h2>Thank you for taking the time to help us improve the platform</h2>
<div class="survey-form">
<form action="none">
<p>
<label for="username">Name</label>
<input type="text" id="username" placeholder="Enter your name" required>
</p>
<p>
<label for="email">Email</label>
<input type="email" id="email" placeholder="Enter your Email" required>
</p>
<p>
<label for="age">Age (optional)</label>
<input type="email" id="age" placeholder="Age">
</p>
</form>
</div>
在我将 body 设置为 display:flex 之前,一切似乎都很好。 h1's、h2's 和我的表格都在同一行。下面是设置显示前后的图片:flex
【问题讨论】: