我開始學習 CSS,他們要求我更改表單的布局,以便欄位水平布局,我必須使用display: flex;這樣的屬性:

但這就是我得到的:

h1 {
font-size: 20px;
letter-spacing: 2px;
margin-bottom: 10px;
margin-top: 10px;
}
body {
background-color: #e0e0e0;
}
section {
padding: 10px;
background-color: white;
}
#prices {
margin: 0;
}
table {
border-collapse: collapse;
}
td,
th {
border: 1px solid black;
padding: 10px;
}
th {
background-color: #2493df;
color: white;
}
ul {
list-style-type: square;
list-style-position: inside;
padding-left: 30px;
}
strong {
color: #2493df;
}
label {
font-size: 16;
font-weight: bold;
}
#buy-form {
background-color: #687373;
margin-top: 10px;
color: #fcfcfc;
display: flex;
}
.form-section {
flex: 1;
}
input[type="number"] {
padding: 2px;
text-align: center;
width: 50px;
}
button {
background-color: #2493df;
font-weight: bold;
font-size: 16px;
color: white;
border: none;
height: 40px;
width: 100%;
}
footer {
font-size: 14px;
color: #595959;
text-align: center;
margin-top: 10px;
}
<section>
<form id="buy-form">
<div class="form-section">
<label for "Adult_t">Adults:</label><br>
<input type="number" id="Adult_t">
<label for "Children_t">Childen:</label><br>
<input type="number" id="Children_t">
<button>Buy</button>
</div>
</form>
</section>
uj5u.com熱心網友回復:
各自嵌套在各自label的. 然后你可以設定并添加一些填充到. 另外,我從按鈕中洗掉了寬度和高度,并改用了填充。inputdiv'sflexform-section#buy-form
h1 {
font-size: 20px;
letter-spacing: 2px;
margin-bottom: 10px;
margin-top: 10px;
}
body {
background-color: #e0e0e0;
}
section {
padding: 10px;
background-color: white;
}
#prices {
margin: 0;
}
table {
border-collapse: collapse;
}
td,
th {
border: 1px solid black;
padding: 10px;
}
th {
background-color: #2493df;
color: white;
}
ul {
list-style-type: square;
list-style-position: inside;
padding-left: 30px;
}
strong {
color: #2493df;
}
label {
font-size: 16;
font-weight: bold;
}
#buy-form {
background-color: #687373;
margin-top: 10px;
color: #fcfcfc;
padding: 10px;
}
.form-section {
display: flex;
justify-content: space-evenly;
}
input[type="number"] {
padding: 2px;
text-align: center;
width: 50px;
}
button {
background-color: #2493df;
font-weight: bold;
font-size: 16px;
color: white;
border: none;
padding: 20px;
}
footer {
font-size: 14px;
color: #595959;
text-align: center;
margin-top: 10px;
}
<section>
<form id="buy-form">
<div class="form-section">
<div>
<label for "Adult_t">Adults:</label><br>
<input type="number" id="Adult_t">
</div>
<div>
<label for "Children_t">Childen:</label><br>
<input type="number" id="Children_t">
</div>
<button>Buy</button>
</div>
</form>
</section>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/452244.html
