我正在制作一个带有注册表单的页面,以供我的ASP.NET网站的新用户创建帐户。我已经从以下URL复制了一个响应式水平CSS表单模板:https://www.templatemonster.com/blog/responsive-css3-form-fields-tutorial。我的网站上使用此表单的页面是https://maxstechandmathsite.azurewebsites.net/Registration。如果您仔细看一下,就会清楚地看到一些样式问题。首先,我将向您展示HTML和CSS的重要部分:
HTML:
<div id="wrapper">
<form runat="server" onsubmit="return false">
<h1>Personal Information</h1>
<span style="float: right; font-size: 1.5em"><span class="red">*</span> Required</span>
<div class="col-4">
<label>
Date of Birth (DOB) <span class="red">*</span>
<input type="date" required="required" placeholder="When is your date of birth?" id="dob" name="dob" tabindex="10" />
</label>
</div>
<div class="col-4">
<label>
Gender <span class="red">*</span>
<select id="gender" required="required" name="gender" tabindex="11">
<option>Male</option>
<option>Female</option>
<option>I do not wish to identify</option>
</select>
</label>
</div>
<div class="col-4 switch">
<label>Send Text Notifications?</label>
<center style="position:relative; padding-bottom: 8px"><input type="checkbox" class="js-switch" /></center>
</div>
<div class="col-4 switch">
<label>Email Updates?</label>
<center style="position:relative; padding-bottom: 8px"><input type="checkbox" class="js-switch" /></center>
</div>
<div id="BottomSection">
<br />
<h1 style="background-color: blueviolet">Login Information</h1>
<asp:CreateUserWizard ID="RegisterUser" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnCreatedUser="CreateUserWizard1_CreatedUser">
</asp:CreateUserWizard>
<div style="text-align: center; font-size: 1.5em">
Enter password hint for future reference:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />I have read and agree to the <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/PrivacyPolicy.html">Privacy Policy</asp:HyperLink> and <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/TermsOfService.html">Terms Of Service</asp:HyperLink>.</div>
<div class="col-submit">
<button class="submitbtn">Submit Form</button>
</div>
</div>
</form>
</div>
CSS:
form > div.switch > label {
padding: 22px 20px 18px;
}
label > input {
display: inline-block;
position: relative;
width: 100%;
height: 27px;
line-height: 27px;
margin: 5px -5px 0;
padding: 7px 5px 3px;
border: none;
outline: none;
color: #555;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-weight: bold;
font-size: 14px;
opacity: .6;
transition: all linear .3s;
}
label > select {
display: block;
width: 100%;
padding: 7px 5px 3px;
margin: 5px -5px 0;
color: #555;
font-weight: 500;
height: 35px;
border: none;
outline: none;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-size: 14px;
opacity: .6;
transition: all linear .3s;
}
如您所见,我已经调整了原始源代码中提供的一些代码,但这只是我为更好而确定的代码,因为在我看来,它与众不同。有关完整的CSS样式表,请转到https://maxstechandmathsite.azurewebsites.net/Style/styles.css。这是我的问题:
1)没有显示h1
标题,甚至没有普通的HTML文本(例如带星号(*)的文本表示该字段为必填字段,ASP.NET复选框旁边的文本),尽管显示了依靠Visual Studio的设计文件。
2)对于最下面的一行,间距和边框显然存在一些问题。出现蓝色边框,但比上面几行的蓝色边框粗,并且还有一些空白,并且底部行的每一列的高度和填充均不均匀。我已经尝试过对许多不同的padding
和margin
值进行调整和试验,但是仍然保持不平衡。最后,我还进行了换行(<br>
),以便在表单字段和ASP.NET CreateUserWizard控件之间留出一定的空间,但也没有应用。
我们将不胜感激。谢谢!
答案 0 :(得分:2)
1)从font-size: 0
选择器中删除form
,以查看标题。
form {
display: block;
margin: 30px;
overflow: hidden;
background: #fff;
border: 3px solid #7eaf4a;
border-radius: 5px;
font-size: 0; /* <- remove this */
}
2)用.col-3, .col-4
和vertical-align: top
更新min-height
选择器,以使它们都具有相同的高度和样式。
.col-3, .col-4 {
border-bottom: 3px solid #0026ff;
border-right: 3px solid #0026ff;
background-color: #ebf442;
vertical-align: top;
min-height: 100px;
}
我已经对<span>Required</span>
元素和媒体查询进行了一些更新,以使响应式设计正常工作,并包含上述修复程序。
下面的代码段:
@import url(http://fonts.googleapis.com/css?family=Laila:400,700);
@import url('https://fonts.googleapis.com/css?family=Damion|Muli:400,600');
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0 auto;
text-align: center;
font-size: 100%;
font: inherit;
vertical-align: baseline;
outline: none;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html { overflow-y: scroll; }
body {
font-family: Arial, Tahoma, sans-serif;
background: #e2eef4;
font-size: 62.5%;
line-height: 1;
padding-top: 40px;
}
.red { color: red }
input, textarea {
-webkit-font-smoothing: antialiased;
outline: none;
}
strong, b { font-weight: bold; }
em, i { font-style: italic; }
h1 {
display: block;
font-size: 3.1em;
line-height: 1.45em;
font-family: 'Laila', serif;
text-align: center;
font-weight: bold;
text-shadow: 1px 1px 0 #fff;
background-color: #ebf442;
}
/** form field **/
form {
display: block;
margin: 30px;
overflow: hidden;
background: #fff;
border: 3px solid #7eaf4a;
border-radius: 5px;
/* font-size: 0; */
}
form > div > label {
display: block;
padding: 20px 20px 10px;
vertical-align: top;
font-size: 13px;
font-weight: bold;
text-transform: uppercase;
color: #939393;
cursor: pointer;
}
form > div.switch > label {
padding: 22px 20px 18px;
}
.col-3, .col-4 {
border-bottom: 3px solid #0026ff !important;
border-right: 3px solid #0026ff !important;
background-color: #ebf442;
vertical-align: top;
min-height: 100px;
}
.col-4 {
float: left;
}
label > input {
display: inline-block;
position: relative;
width: 100%;
height: 27px;
line-height: 27px;
margin: 5px -5px 0;
padding: 7px 5px 3px;
border: none;
outline: none;
color: #555;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-weight: bold;
font-size: 14px;
opacity: .6;
transition: all linear .3s;
}
label > select {
display: block;
width: 100%;
padding: 7px 5px 3px;
margin: 5px -5px 0;
color: #555;
font-weight: 500;
height: 35px;
border: none;
outline: none;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-size: 14px;
opacity: .6;
transition: all linear .3s;
}
.col-submit {
text-align: center;
padding: 20px;
}
label > input:focus, label > select:focus {
opacity: 1;
}
/** button design based on http://codepen.io/guvootes/pen/eyDAb **/
button {
width: 100%;
height: 35px;
border: none;
border-radius: 4px;
margin: 0 0 15px 0;
font-size: 14px;
color: #fff;
font-weight: bold;
text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
overflow: hidden;
outline: none;
}
button.submitbtn {
background-image: -moz-linear-gradient(#97c16b, #8ab959);
background-image: -webkit-linear-gradient(#97c16b, #8ab959);
background-image: linear-gradient(#97c16b, #8ab959);
border-bottom: 1px solid #648c3a;
cursor: pointer;
color: #fff;
}
button.submitbtn:hover {
background-image: -moz-linear-gradient(#8ab959, #7eaf4a);
background-image: -webkit-linear-gradient(#8ab959, #7eaf4a);
background-image: linear-gradient(#8ab959, #7eaf4a);
}
button.submitbtn:active {
height: 34px;
border-bottom: 0;
margin: 1px 0 0 0;
background-image: -moz-linear-gradient(#7eaf4a, #8ab959);
background-image: -webkit-linear-gradient(#7eaf4a, #8ab959);
background-image: linear-gradient(#7eaf4a, #8ab959);
-moz-box-shadow: inset 0 1px 3px 1px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: inset 0 1px 3px 1px rgba(0, 0, 0, 0.3);
box-shadow: inset 0 1px 3px 1px rgba(0, 0, 0, 0.3);
}
#BottomSection {
background-color: #e4e4e4;
display: block;
}
/** responsive design **/
@media(min-width: 150px) {
form > div {
display: inline-block;
}
.col-submit {
display: block;
}
.col-2, .col-3, .col-4 {
box-shadow: 1px 1px #0026ff;
border-bottom: 1px solid #0026ff;
border-right: 1px solid #0026ff;
}
.col-2 {
width: 50%
}
.col-3 {
width: 33.3333333333%
}
.col-4 {
width: 25%
}
.col-submit button {
width: 30%;
margin: 0 auto;
}
}
@media (max-width: 640px) {
#app_body {
padding-left: 0 !important
}
#main_fields div.field label, #eeoc_fields div.field label {
float: none !important;
width: 100% !important;
text-align: left !important;
display: block !important
}
#main_fields .field-error-msg {
padding-left: 0 !important
}
#education_section .select2-container, #custom_fields .select2-container, #custom_fields div.field input[type=text], #custom_fields div.field textarea, #custom_fields div.field select, #main_fields div.field input[type=text], #main_fields div.field textarea, #eeoc_fields div.field input[type=text], #eeoc_fields div.field textarea {
width: 100% !important;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box
}
#eeoc_fields div.field select, #custom_fields div.field select {
width: 100% !important
}
.accessible #header {
padding-right: 0
}
.accessible #resume_paste, .accessible #cover_letter_paste {
margin-left: 0 !important
}
.accessible div.required-fields {
bottom: auto;
left: auto;
right: 30px;
top: 30px
}
.accessible #custom_fields .field label:not(:first-child) {
margin-top: 15px;
display: inline-block
}
.accessible #main_fields div.field textarea.paste, .accessible #eeoc_fields div.field textarea.paste {
margin-left: 0
}
.accessible #main_fields .employment .field input[type='checkbox'] {
margin-left: 0 !important
}
.accessible #main_fields .employment .field label.current {
display: inline-block !important;
width: auto !important
}
.accessible .filter-container select {
width: 100% !important
}
.accessible .locate-me, .accessible .year {
margin-top: 10px !important
}
.accessible #add_education, .accessible #add_employment {
margin: 0 !important
}
.accessible .remove-background-field {
position: absolute;
margin: 0;
top: -15px;
right: 0
}
.col-4 {
width: 100%;
}
}
<div id="wrapper">
<form runat="server" onsubmit="return false">
<h1>Personal Information</h1>
<span style="font-size: 1.5em; position: absolute; z-index: 1; right: 40px;">
<span class="red">*</span>
<span> Required</span>
</span>
<div class="col-4">
<label>
Date of Birth (DOB) <span class="red">*</span>
<input type="date" required="required" placeholder="When is your date of birth?" id="dob" name="dob" tabindex="10" />
</label>
</div>
<div class="col-4">
<label>
Gender <span class="red">*</span>
<select id="gender" required="required" name="gender" tabindex="11">
<option>Male</option>
<option>Female</option>
<option>I do not wish to identify</option>
</select>
</label>
</div>
<div class="col-4 switch">
<label>Send Text Notifications?</label>
<center style="position:relative; padding-bottom: 8px"><input type="checkbox" class="js-switch" /></center>
</div>
<div class="col-4 switch">
<label>Email Updates?</label>
<center style="position:relative; padding-bottom: 8px"><input type="checkbox" class="js-switch" /></center>
</div>
<div id="BottomSection">
<br />
<h1 style="background-color: blueviolet">Login Information</h1>
<asp:CreateUserWizard ID="RegisterUser" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnCreatedUser="CreateUserWizard1_CreatedUser">
</asp:CreateUserWizard>
<div style="text-align: center; font-size: 1.5em">
Enter password hint for future reference:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />I have read and agree to the <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/PrivacyPolicy.html">Privacy Policy</asp:HyperLink> and <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/TermsOfService.html">Terms Of Service</asp:HyperLink>.</div>
<div class="col-submit">
<button class="submitbtn">Submit Form</button>
</div>
</div>
</form>
</div>