gpt4 book ai didi

javascript - 如何为带有验证的表单中的所有字段提供相等的宽度?

转载 作者:太空宇宙 更新时间:2023-11-03 19:59:21 25 4
gpt4 key购买 nike

在下面的 HTML5 表单代码中,如何为所有名称和输入字段赋予相同的宽度,以便所有名称在同一列中对齐,所有输入类型字段在同一列中以相同的宽度对齐?

HTML代码:

<!DOCTYPE html>

<html>

<head>
<title>CSS Contact Form</title>

<meta charset="utf-8" />

<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>

<body style=" background-color:#E5E4E2">

<h2>Registration Form</h2>
<div style="margin-left:420px; border:1px solid #ccc; width:400px; padding:15px; border-radius:5px;">
<form class="form">

<p class="name">
<label for="name"> First Name *:</label>
<input type="text" name="fname" id="fname" placeholder="John" required/>
</p>

<p class="name">
<label for="name">Last Name *:</label>
<input type="text" name="lname" id="lname" placeholder="Maxwell" required/>

</p>

<p class="web">
<label for="web">Company Name *:</label>
<input type="text" name="web" id="web" placeholder="BDI Systems & Technologies" required/>

</p>

<p class="email">
<label for="email">Email Id *:</label>
<input type="text" name="email" id="email" placeholder="mail@bdisys.com" required/>
</p>

<p class="budget">
<label for="name">Budget :</label>
<input type="text" name="budget" id="budget" placeholder="200000"/>

</p>

<p class="submit">
<input type="submit" value="Send" />
</p>

</form>
</div>
</body>

</html>

CSS:

body {
padding: 100px 100px;
font-size: 13px;
font-style: Verdana, Tahoma, sans-serif;
}

h2 {
margin-bottom: 20px;
color: #474E69;
margin-left:420px;
}

/* ===========================
====== Contact Form =======
=========================== */

input, textarea {
padding: 10px;
border: 1px solid #E5E5E5;
width: 200px;
color: #999999;
box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-moz-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
-webkit-box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 8px;
}

textarea {
width: 400px;
height: 150px;
max-width: 400px;
line-height: 18px;
}

input:hover, textarea:hover,
input:focus, textarea:focus {
border-color: 1px solid #C9C9C9;
box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 8px;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 8px;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 0px 8px;
}

.form label {
margin-left: 10px;
color: #999999;
}

/* ===========================
====== Submit Button ======
=========================== */

.submit input {
width: 100px;
height: 40px;
background-color: #474E69;
color: #FFF;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}

最佳答案

JSBIN

只需添加 display: inline-block 并指定标签元素的最小宽度

.form label {
display: inline-block;
margin-left: 10px;
color: #999999;
min-width: 110px;
}

关于javascript - 如何为带有验证的表单中的所有字段提供相等的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23403038/

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