gpt4 book ai didi

html - 居中表单 - CSS

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:50 25 4
gpt4 key购买 nike

我正在处理的表格有两个问题。问题一是我无法让表单在页面中居中。第二个问题是我的提交按钮不会在表单内居中。

fieldset {
display: block;
margin: 0 auto;
border: 1px solid rgb(233, 69, 0);
width: 40%;
}
legend {
background-color: rgb(233, 69, 0);
color: white;
padding: 3px 0px;
text-indent: 5px;
width: 100%;
}
label {
clear: left;
display: block;
float: left;
font-size: 0.9em;
margin: 7px 4% 7px 5px;
width: 40%;
}
input {
display: block;
font-size: 0.9em;
margin: 7px 0px;
width: 50%;
}
textarea {
display: block;
font-size: 0.9em;
float: left;
height: 150px;
margin: 10px 0px;
width: 600%;
}
form p {
text-align: center;
}
input[type="submit"] {
display: block;
float: none;
height: 40px;
width: 200px;
}
input:focus,
select:focus,
textarea:focus {
background-color: rgb(220, 255, 220);
}
input:focus:valid {
background-color: rgb(220, 255, 220) url("go.png") bottom right no-repeat;
-o-background-size: contain;
-moz-background-size: contain;
-webkit-background-size: contain;
background-size: contain;
}
input:focus:invalid {
background-color: rgb(255, 232, 233) url("stop.png") bottom right no-repeat;
-o-background-size: contain;
-moz-background-size: contain;
-webkit-background-size: contain;
background-size: contain;
}
<section>
<p>Please type in your information so I can send you the newsletter.
<br>Required values are marked by an asterisk (*)</p>
<form id="newsletter" onsubmit="return validateForm()" method="post">
<fieldset id="personal">
<legend>Personal Information</legend>
<label for="name">Name: *</label>
<input type="text" name="name" id="name" size="40">
<br>
<label for="eMail">E-mail Address: *</label>
<input type="text" name="eMail" id="eMail">
<br>
<label for="favBeer">Favorite Beer Style:</label>
<select name="favBeer" id="favBeer">
<option value="IPA">IPA</option>
<option value="Saison">Saison</option>
<option value="Porter">Porter</option>
<option value="Pilsner">Pilsner</option>
<option value="Hefeweizen">Hefeweizen</option>
<option value="Stout">Stout</option>
<option value="Other">Other</option>
</select>
<br>
<label for="comments">Additional Information:
<label>
<textarea name="comments" id="comments" cols="55" rows="5"></textarea>
<div class="button">
<input type="submit" value="Sign Me Up" />
</div>
</fieldset>

</section>

最佳答案

你不关闭最后两个<label>在任何地方。正确的代码是:

  <label for="comments">Additional Information:
<label>
<textarea name="comments" id="comments" cols="55" rows="5></textarea>
</label>
</label>

<div class="button">
<input type="submit" value="Sign Me Up" />
</div>
</fieldset>

您需要编辑 css 以使用 clear 将按钮保留在底部并使按钮居中:

.button {      /*     */
clear: left; /* NEW */
} /* */

input[type="submit"] {
display: block;
float: none;
height: 40px;
width: 200px;
margin: 0 auto; /* NEW */
}

工作示例:https://jsfiddle.net/m0g9tzxz/1/embedded/result/

关于html - 居中表单 - CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33574184/

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