2016-03-27 93 views
1

所以我有这个HTML和CSS,我试图建立一个窗体。 一切都很好,除了关于“电子邮件”输入框,它应该在“名称”输入框下面,不在同一行。我的html表格的框尺寸没有合适的尺寸

从浏览器使用"Inspect Element",我注意到名称的标签标签有height=0px,下一个标签(电子邮件)有height=61px。问题与这两个标签有关。有人可以帮助我吗?我是初学者与CSS,我会很感激任何帮助。

<!DOCTYPE html> 
<html> 
<head> 
<title></title> 

<meta name="viewport" content="width=device-width"/> 
<meta charset="UTF-8"> 

<link type="text/css" rel="stylesheet" href="style.css"> 
<link href='http://fonts.googleapis.com/css?family=Rokkitt:400,700|Lato:400,300' rel='stylesheet' type='text/css'> 

</head> 
<body id="top"> 
<div id="cv" class="instaFade"> 


     <script  src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
     <script type="text/javascript"> 
     $(document).ready(function() { 
      $("#submit_btn").click(function() { 

       var proceed = true; 
       //simple validation at client's end 
       //loop through each field and we simply change border color to red for invalid fields  
       $("#contact_form input[required=true], #contact_form textarea[required=true]").each(function(){ 
        $(this).css('border-color',''); 
        if(!$.trim($(this).val())){ //if this field is empty 
         $(this).css('border-color','red'); //change border color to red 
         proceed = false; //set do not proceed flag 
        } 
        //check invalid email 
        var email_reg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/; 
        if($(this).attr("type")=="email" && !email_reg.test($.trim($(this).val()))){ 
         $(this).css('border-color','red'); //change border color to red 
         proceed = false; //set do not proceed flag    
        } 
       }); 

       if(proceed) //everything looks good! proceed... 
       { 
        //data to be sent to server   
        var m_data = new FormData();  
        m_data.append('user_name', $('input[name=name]').val()); 
        m_data.append('user_email', $('input[name=email]').val()); 

        //instead of $.post() we are using $.ajax() 
        //that's because $.ajax() has more options and flexibly. 
        $.ajax({ 
         url: 'x', 
         data: m_data, 
         processData: false, 
         contentType: false, 
         type: 'POST', 
         dataType:'json', 
         success: function(response){ 
         //load json data from server and output message  
         if(response.type == 'error'){ //load json data from server and output message  
          output = '<div class="error">'+response.text+'</div>'; 
         }else{ 
          output = '<div class="success">'+response.text+'</div>'; 
         } 
         $("#contact_form #contact_results").hide().html(output).slideDown(); 
         } 
        }); 


       } 
      }); 

      //reset previously set border colors and hide all message on .keyup() 
      $("#contact_form input[required=true], #contact_form textarea[required=true]").keyup(function() { 
       $(this).css('border-color',''); 
       $("#result").slideUp(); 
      }); 
     }); 
     </script> 

     <div class="form-style" id="contact_form"> 
      <div class="form-style-heading">test</div> 
      <div id="contact_results"></div> 
      <div id="contact_body"> 
       <label> 
        <span>Name <span class="required">*</span></span> 
        <input type="text" name="name" id="name" required="true" class="input-field"/> 
       </label> 
       <label> 
        <span>Email <span class="required">*</span></span> 
        <input type="email" name="email" required="true" class="input-field"/> 
       </label> 
       <label> 
        <span>Phone <span class="required">*</span></span> 
        <input type="text" name="phone1" maxlength="4" placeholder="+91" required="true" class="tel-number-field"/>&mdash; 
        <input type="text" name="phone2" maxlength="15" required="true" class="tel-number-field long" /> 
       </label> 
       <label><span>Attachment</span> 
        <input type="file" name="file_attach" class="input-field" /> 
       </label> 

       <label for="subject"><span>Regarding</span> 
        <select name="subject" class="select-field"> 
         <option value="General Question">General Question</option> 
         <option value="Advertise">Advertisement</option> 
         <option value="Partnership">Partnership Oppertunity</option> 
        </select> 
       </label> 
       <label for="field5"><span>Message <span class="required">*</span></span> 
        <textarea name="message" id="message" class="textarea-field" required="true"></textarea> 
       </label> 
       <label> 
        <span>&nbsp;</span><input type="submit" id="submit_btn" value="Submit" /> 
       </label> 
      </div> 
     </div> 


</body> 
</html> 

和我的style.css

html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,abbr,address,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,var,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,time,mark,audio,video { 
    border:0; 
    font:inherit; 
    font-size:100%; 
    margin:0; 
    padding:0; 
    vertical-align:baseline; 
} 

article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section { 
    display:block; 
} 

html, body {background: #181818; font-family: 'Lato', helvetica, arial, sans-serif; font-size: 16px; color: #222;} 

.clear {clear: both;} 

p { 
    font-size: 1em; 
    line-height: 1.4em; 
    margin-bottom: 20px; 
    color: #444; 
} 

#cv { 
    width: 90%; 
    max-width: 800px; 
    background: #f3f3f3; 
    margin: 30px auto; 
} 

.mainDetails { 
    padding: 25px 35px; 
    border-bottom: 2px solid #cf8a05; 
    background: #ededed; 
} 

#name h1 { 
    font-size: 2.5em; 
    font-weight: 700; 
    font-family: 'Rokkitt', Helvetica, Arial, sans-serif; 
    margin-bottom: -6px; 
} 

#name h2 { 
    font-size: 2em; 
    margin-left: 2px; 
    font-family: 'Rokkitt', Helvetica, Arial, sans-serif; 
} 

#mainArea { 
    padding: 0 40px; 
} 

#headshot { 
    width: 12.5%; 
    float: left; 
    margin-right: 30px; 
} 

#headshot img { 
    width: 100%; 
    height: auto; 
    -webkit-border-radius: 50px; 
    border-radius: 50px; 
} 

#name { 
    float: left; 
} 

#contactDetails { 
    float: right; 
} 

#contactDetails ul { 
    list-style-type: none; 
    font-size: 0.9em; 
    margin-top: 2px; 
} 

#contactDetails ul li { 
    margin-bottom: 3px; 
    color: #444; 
} 

#contactDetails ul li a, a[href^=tel] { 
    color: #444; 
    text-decoration: none; 
    -webkit-transition: all .3s ease-in; 
    -moz-transition: all .3s ease-in; 
    -o-transition: all .3s ease-in; 
    -ms-transition: all .3s ease-in; 
    transition: all .3s ease-in; 
} 

#contactDetails ul li a:hover { 
    color: #cf8a05; 
} 


section { 
    border-top: 1px solid #dedede; 
    padding: 20px 0 0; 
} 

section:first-child { 
    border-top: 0; 
} 

section:last-child { 
    padding: 20px 0 10px; 
} 

.sectionTitle { 
    float: left; 
    width: 25%; 
} 

.sectionContent { 
    float: right; 
    width: 72.5%; 
} 

.sectionTitle h1 { 
    font-family: 'Rokkitt', Helvetica, Arial, sans-serif; 
    font-style: italic; 
    font-size: 1.5em; 
    color: #cf8a05; 
} 

.sectionContent h2 { 
    font-family: 'Rokkitt', Helvetica, Arial, sans-serif; 
    font-size: 1.5em; 
    margin-bottom: -2px; 
} 

.subDetails { 
    font-size: 0.8em; 
    font-style: italic; 
    margin-bottom: 3px; 
} 

.keySkills { 
    list-style-type: none; 
    -moz-column-count:4; 
    -webkit-column-count:4; 
    column-count:4; 
    margin-bottom: 20px; 
    font-size: 1em; 
    color: #444; 
} 

.keySkills ul li { 
    margin-bottom: 3px; 
} 

@media all and (min-width: 602px) and (max-width: 800px) { 
    #headshot { 
     display: none; 
    } 

    .keySkills { 
     -moz-column-count:2; 
     -webkit-column-count:2; 
     column-count:2; 
    } 
} 

@media all and (max-width: 601px) { 
    #cv { 
     width: 95%; 
     margin: 10px auto; 
     min-width: 280px; 
    } 

    #headshot { 
     display: none; 
    } 

    #name, #contactDetails { 
     float: none; 
     width: 100%; 
     text-align: center; 
    } 

    .sectionTitle, .sectionContent { 
     float: none; 
     width: 100%; 
    } 

    .sectionTitle { 
     margin-left: -2px; 
     font-size: 1.25em; 
    } 

    .keySkills { 
     -moz-column-count:2; 
     -webkit-column-count:2; 
     column-count:2; 
    } 
} 

@media all and (max-width: 480px) { 
    .mainDetails { 
     padding: 15px 15px; 
    } 

    section { 
     padding: 15px 0 0; 
    } 

    #mainArea { 
     padding: 0 25px; 
    } 


    .keySkills { 
     -moz-column-count:1; 
     -webkit-column-count:1; 
     column-count:1; 
    } 

    #name h1 { 
     line-height: .8em; 
     margin-bottom: 4px; 
    } 
} 

@media print { 
    #cv { 
     width: 100%; 
    } 
} 

@-webkit-keyframes reset { 
    0% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 0; 
    } 
} 

@-webkit-keyframes fade-in { 
    0% { 
     opacity: 0; 
    } 
    40% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 1; 
    } 
} 

@-moz-keyframes reset { 
    0% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 0; 
    } 
} 

@-moz-keyframes fade-in { 
    0% { 
     opacity: 0; 
    } 
    40% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 1; 
    } 
} 

@keyframes reset { 
    0% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 0; 
    } 
} 

@keyframes fade-in { 
    0% { 
     opacity: 0; 
    } 
    40% { 
     opacity: 0; 
    } 
    100% { 
     opacity: 1; 
    } 
} 

.instaFade { 
    -webkit-animation-name: reset, fade-in; 
    -webkit-animation-duration: 1.5s; 
    -webkit-animation-timing-function: ease-in; 

    -moz-animation-name: reset, fade-in; 
    -moz-animation-duration: 1.5s; 
    -moz-animation-timing-function: ease-in; 

    animation-name: reset, fade-in; 
    animation-duration: 1.5s; 
    animation-timing-function: ease-in; 
} 

.quickFade { 
    -webkit-animation-name: reset, fade-in; 
    -webkit-animation-duration: 2.5s; 
    -webkit-animation-timing-function: ease-in; 

    -moz-animation-name: reset, fade-in; 
    -moz-animation-duration: 2.5s; 
    -moz-animation-timing-function: ease-in; 

    animation-name: reset, fade-in; 
    animation-duration: 2.5s; 
    animation-timing-function: ease-in; 
} 

.delayOne { 
    -webkit-animation-delay: 0, .5s; 
    -moz-animation-delay: 0, .5s; 
    animation-delay: 0, .5s; 
} 

.delayTwo { 
    -webkit-animation-delay: 0, 1s; 
    -moz-animation-delay: 0, 1s; 
    animation-delay: 0, 1s; 
} 

.delayThree { 
    -webkit-animation-delay: 0, 1.5s; 
    -moz-animation-delay: 0, 1.5s; 
    animation-delay: 0, 1.5s; 
} 

.delayFour { 
    -webkit-animation-delay: 0, 2s; 
    -moz-animation-delay: 0, 2s; 
    animation-delay: 0, 2s; 
} 

.delayFive { 
    -webkit-animation-delay: 0, 2.5s; 
    -moz-animation-delay: 0, 2.5s; 
    animation-delay: 0, 2.5s; 
} 

/* form style */ 
.form-style{ 
    max-width: 450px; 
    padding: 40px 30px 40px 40px; 
    font: 13px Arial, Helvetica, sans-serif; 
    margin: 20px auto; 
    background: #FFFFFF; 
    border-radius: 5px; 
    -webkit-border-radius:5px; 
    -moz-border-radius:5px; 
    box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2); 
    -moz-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2); 
    -webkit-box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2); 
} 
.form-style-heading{ 
    font-weight: bold; 
    font-style: italic; 
    border-bottom: 2px solid #ddd; 
    margin-bottom: 10px; 
    font-size: 15px; 
    padding-bottom: 3px; 
} 
.form-style label{ 
    display: block; 
    margin: 0px 0px 15px 0px; 
} 
.form-style label > span{ 
    width: 100px; 
    font-weight: bold; 
    float: left; 
    padding-top: 8px; 
    padding-right: 5px; 
} 
.form-style span.required{ 
    color:red; 
} 
.form-style .tel-number-field{ 
    width: 40px; 
    text-align: center; 
} 
.form-style .long{ 
    width: 120px; 
} 
.form-style input.input-field{ 
    width: 48%; 
} 

.form-style input.input-field, 
.form-style .tel-number-field, 
.form-style .textarea-field, 
.form-style .select-field{ 
    -webkit-transition: all 0.30s ease-in-out; 
    -moz-transition: all 0.30s ease-in-out; 
    -ms-transition: all 0.30s ease-in-out; 
    -o-transition: all 0.30s ease-in-out; 
    box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    border: 1px solid #C2C2C2; 
    box-shadow: 1px 1px 4px #EBEBEB; 
    -moz-box-shadow: 1px 1px 4px #EBEBEB; 
    -webkit-box-shadow: 1px 1px 4px #EBEBEB; 
    border-radius: 3px; 
    -webkit-border-radius: 3px; 
    -moz-border-radius: 3px; 
    padding: 7px; 
    outline: none; 
} 
.form-style .input-field:focus, 
.form-style .tel-number-field:focus, 
.form-style .textarea-field:focus, 
.form-style .select-field:focus{ 
    border: 1px solid #0C0; 
} 
.form-style .textarea-field{ 
    height:100px; 
    width: 55%; 
} 
.form-style input[type="button"], 
.form-style input[type="submit"] { 
    -moz-box-shadow: inset 0px 1px 0px 0px #f3f3f3; 
    -webkit-box-shadow: inset 0px 1px 0px 0px #f3f3f3; 
    box-shadow: inset 0px 1px 0px 0px #f3f3f3; 
    background-color: #f3f3f3; 
    border: 1px solid #f3f3f3; 
    display: inline-block; 
    cursor: pointer; 
    color: #000000; 
    padding: 8px 18px; 
    text-decoration: none; 
    font: 12px Arial, Helvetica, sans-serif; 
} 
.form-style input[type="button"]:hover, 
.form-style input[type="submit"]:hover { 
    background: linear-gradient(to bottom, #f3f3f3 5%, #FFFFFF 100%); 
    background-color: #28739E; 
} 
.form-style .success{ 
    background: #D8FFC0; 
    padding: 5px 10px 5px 10px; 
    margin: 0px 0px 5px 0px; 
    border: none; 
    font-weight: bold; 
    color: #2E6800; 
    border-left: 3px solid #2E6800; 
} 
.form-style .error { 
    background: #FFE8E8; 
    padding: 5px 10px 5px 10px; 
    margin: 0px 0px 5px 0px; 
    border: none; 
    font-weight: bold; 
    color: #FF0000; 
    border-left: 3px solid #FF0000; 
} 

回答

0

所有你需要的是clear: both因为.form-style label > spanfloat

.form-style label { 
    clear: both; 
} 

jsFiddle

备注:不错的表格!

+0

谢谢@jiff。 它工作完美 – jimmy