gpt4 book ai didi

css - 我怎样才能将我的标签和文本框对齐到中心? CSS

转载 作者:太空宇宙 更新时间:2023-11-04 10:19:40 24 4
gpt4 key购买 nike

我目前有以下表格

enter image description here

使用以下 CSS:

#myForm form {
background-color: #E0E0E0;
text-align: center;
}
#myForm label {
display: inline-block;
text-align: right;
clear: left;
width: 150px;
text-align: right;
}
#myForm input {
display: inline-block;
text-align: center;
}
#myForm select {
display: inline-block;
text-align: center;
}

html div 示例:

<div id = "myForm">
<form>
<p> <label for="username">Username: </label>
<input type="text" id="username" name="username" size=20 /></p>
</p>
</form>

我怎么能让我的标签和文本框居中,因为它看起来有点偏离中心。另外,我怎样才能使灰色背景成为一个居中的框,而不是占据整个屏幕的宽度。

最佳答案

试试这个 css,可能对你有帮助,看看 fiddle 链接:

CSS:

label {
float: left;
text-align: center;
width: 50%;
}
p {
float: none;
margin: 10px auto;
width: 50%;
}
form {
background-color: red;
float: left;
margin: 0 auto;
width: 100%;
}

参见 FIDDLE

关于css - 我怎样才能将我的标签和文本框对齐到中心? CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36931388/

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