gpt4 book ai didi

html - 将 HTML 元素与 CSS 对齐

转载 作者:行者123 更新时间:2023-11-28 17:29:22 24 4
gpt4 key购买 nike

我必须设计一个简单的 HTML 文档。两个标签必须位于左侧,下拉框必须居中,图像必须位于右侧。到目前为止,我已经试过了,但它不能正常工作。总有一个元素没有正确对齐。请帮我?提前致谢。

.fist_section label {
position: left
width: 30%;
}

.fist_section select {
position: center;
width: 40%;
}

.first_section img {
float: right;
}
<form>
<div class="first_section">
<img src="../img/img.jpg">
<label>Automobile:</lable>
<select class="fist_section_dropdown">
<option value="bmw">BMW</option>
</select>
<br>
<label>Automobile:</label>
<select class="fist_section_dropdown">
<option value="mercedes">Mercedes</option>
</select>
</div>
</form>

最佳答案

此处错别字太多,例如.fist_section应该是 .first_section , <\lable>应该是 </label> , 等等。

position不用于对齐,而是用于定义 absoluterelative定位。你真正需要在这里写的是 float: left; .

.first_section label {
float: left;
width: 30%;
}

.first_section select {
width: 40%;
}

.first_section img {
float: right;
}
<form>
<div class="first_section">
<img src="../img/img.jpg">
<label>Automobile:</label>
<select class="first_section_dropdown">
<option value="bmw">BMW</option>
</select>
<br>
<label>Automobile:</label>
<select class="first_section_dropdown">
<option value="mercedes">Mercedes</option>
</select>
</div>
</form>

关于html - 将 HTML 元素与 CSS 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37567335/

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