我有这个HTML和css代码是一个Form ...
我尝试了在其他问题中找到的其他解决方案,但我无法将input
和labels
“垂直对齐”......
任何人都可以帮助我吗?
PS。:在我的浏览器(Firefox
)中,它看起来像这张图片......
<style type="text/css">.modal {
background-color: rgba(0, 0, 0, 0.4);
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
position: fixed;
color: #B1EBF9;
}
.close {
color: #111;
float: right;
font-size: 28px;
font-weight: bold;
}
#divMain,
.post-menu {
filter: blur(5px);
}
.close:hover,
.close:focus {
color: red;
text-decoration: none;
cursor: pointer;
}
.modal-content {
background-color: #3B474C;
float: center;
/* border: 1px solid #000;
*/
width: 35%;
height: 35%;
padding: 1%;
opacity: 1;
margin-left: 40%;
margin-right: 40%;
margin-top: 20%;
margin-bottom: 20%;
text-align: center;
border-radius: 15px;
}
#up input {
/*background-color: #546E7A;*/
text-align: center;
appearance: none;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] {
-moz-appearance: textfield;
min: 0;
}
input {
background-color: #3B474C;
color: #B1EBF9;
border: 2px #28C953 solid;
border-radius: 50px;
padding-top: 2%;
padding-bottom: 2%;
margin-top: 1%;
}
#buttonUpdate {
background-color: #28C953;
margin-top: 3%;
border: 2px #28C953 solid;
border-radius: 50px;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 6%;
padding-right: 6%;
color: #3B474C;
font-weight: bold;
}
</style>
<div id="popup" class="modal" onclick="if (event.target == document.getElementById('popup')){window.location = '/dashboard/clientBackup/';}">
<div class="modal-content">
<form action="" method="post">
<div id="up">
<input name="csrfmiddlewaretoken" value="S90LWPAUTykZXspFHHUQ1JXCBRnzXHK2PfgDvTO2mShTEzxI1csOWLQRQbQQgt5q" type="hidden">
<p>
<label for="id_identificador">Identificador:</label>
<input name="identificador" value="devserver-fd" required="" id="id_identificador" maxlength="200" type="text">
</p>
<p>
<label for="id_email">Email:</label>
<input name="email" value="example@example.com" required="" id="id_email" maxlength="200" type="text">
</p>
<p>
<label for="id_n_jobs">N jobs:</label>
<input name="n_jobs" value="1" required="" id="id_n_jobs" type="number">
</p>
</div>
<input id="buttonUpdate" value="Update" type="submit"><br>
</form>
</div>
</div>
答案 0 :(得分:1)
不确定为什么您有<p>
个标签作为输入+标签的容器而不是<div>
,但我只是使用display: flex;
和flex-direction: column;
来垂直定位。< / p>
所以form p
的最后一种风格是我唯一改变的方式。
如果您想要左对齐的标签,例如只需添加:
form p label {
align-self: flex-start;
}
<style type="text/css">.modal {
background-color: rgba(0, 0, 0, 0.4);
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
position: fixed;
color: #B1EBF9;
}
.close {
color: #111;
float: right;
font-size: 28px;
font-weight: bold;
}
#divMain,
.post-menu {
filter: blur(5px);
}
.close:hover,
.close:focus {
color: red;
text-decoration: none;
cursor: pointer;
}
.modal-content {
background-color: #3B474C;
float: center;
/* border: 1px solid #000;
*/
width: 35%;
height: 35%;
padding: 1%;
opacity: 1;
margin-left: 40%;
margin-right: 40%;
margin-top: 20%;
margin-bottom: 20%;
text-align: center;
border-radius: 15px;
}
#up input {
/*background-color: #546E7A;*/
text-align: center;
appearance: none;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type=number] {
-moz-appearance: textfield;
min: 0;
}
input {
background-color: #3B474C;
color: #B1EBF9;
border: 2px #28C953 solid;
border-radius: 50px;
padding-top: 2%;
padding-bottom: 2%;
margin-top: 1%;
}
#buttonUpdate {
background-color: #28C953;
margin-top: 3%;
border: 2px #28C953 solid;
border-radius: 50px;
padding-top: 2%;
padding-bottom: 2%;
padding-left: 6%;
padding-right: 6%;
color: #3B474C;
font-weight: bold;
}
form p {
display: flex;
flex-direction: column;
}
</style>
<div id="popup" class="modal" onclick="if (event.target == document.getElementById('popup')){window.location = '/dashboard/clientBackup/';}">
<div class="modal-content">
<form action="" method="post">
<div id="up">
<input name="csrfmiddlewaretoken" value="S90LWPAUTykZXspFHHUQ1JXCBRnzXHK2PfgDvTO2mShTEzxI1csOWLQRQbQQgt5q" type="hidden">
<p>
<label for="id_identificador">Identificador:</label>
<input name="identificador" value="devserver-fd" required="" id="id_identificador" maxlength="200" type="text">
</p>
<p>
<label for="id_email">Email:</label>
<input name="email" value="example@example.com" required="" id="id_email" maxlength="200" type="text">
</p>
<p>
<label for="id_n_jobs">N jobs:</label>
<input name="n_jobs" value="1" required="" id="id_n_jobs" type="number">
</p>
</div>
<input id="buttonUpdate" value="Update" type="submit"><br>
</form>
</div>
</div>