2016-03-01 44 views
0

我有一個窗體不會在它結束前標記爲DIFF。它驗證了CSS和HTML驗證器的正確性,但是我對某些字段的CSS有問題。如果您看到HTML,我將表單分成兩列。 表格字段集標籤在左列中開始並在右列中關閉。出於某種原因,CSS似乎不適用於右列中的字段。窗體分割跨越DIV - CSS不起作用

This SO Question and it's answers對我的問題沒有解決方案。

下面是HTML:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>Welcome</title> 
    <meta charset="utf-8"> 
    <link rel="stylesheet" href="css/grid.css" type="text/css" media="all"> 
    <link rel="stylesheet" href="css/new.css" type="text/css" media="all"> 
</head> 
<body> 
<div class="container_24"> 
    <article id="content"> 
     <ul> 
      <li id="Shipping"> 
       <div class="wrapper baseform line2"> 
       <div id="information"> 
        <span class="bg"></span> 
       </div> 
       <div class="grid_6 prefix_1 omega"> 
        <h2>Shipping & Billing</h2> 
        <form action="billing.php#!/Billing" method="post" id="GenericForm"> 
         <fieldset> 
         <h3>Shipping Information</h3> 
         <div class="wrapper"> 
          <div class="floatleft"> 
           <label id="lblfname"> 
           <span class="bg"><input id="fname" name="fname" type="text" value="" placeholder="First Name:" class="input"></span></label></div> 
          <div class="floatleft"> 
           <label id="lbllname"> 
           <span class="bg"><input id="lname" name="lname" type="text" value="" placeholder="Last Name:" class="input"></span></label></div> 
          <div class="floatleft"> 
           <label><span></span></label></div> 
         </div> 
         <div class="wrapper"> 
          <div class="floatleft"> 
           <label id="lblEmail"> 
           <span class="bg"><input id="Email" name="Email" type="text" value="" placeholder="Email:" class="input"></span> 
           <span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span> </label> 
          </div> 
          <div class="floatleft"> 
           <label id="lblMobilePhone"> 
           <span class="bg"><input id="MobilePhone" name="MobilePhone" type="text" value="" placeholder="Mobile Phone:" class="input"></span> 
           <span class="error">*This is not a valid phone number.</span></label></div> 
          <div class="floatleft"> 
           <label id="lblOtherPhone"> 
           <span class="bg"><input id="OtherPhone" name="OtherPhone" type="text" value="" placeholder="Other Phone:" class="input"></span> 
           <span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span> </label></div> 
         </div> 
         <div class="wrapper"> 
          <div class="floatleft"> 
           <label id="lblAddress1"> 
           <span class="bg"><input id="Address1" name="Address1" type="text" value="" placeholder="Address Line1:" class="input"></span> 
           <span class="error">*This is not a valid URL.</span> <span class="empty">*This field is required.</span> </label></div> 
          <div class="floatleft"> 
           <label id="lblAddress2"> 
           <span class="bg"><input id="Address2" name="Address2" type="text" value="" placeholder="Address Line2:" class="input"></span></label></div> 
          <div class="floatleft"> 
           <label id="lblCity"> 
           <span class="bg"><input id="City" name="City" type="text" value="" placeholder="City:" class="input"></span></label></div> 
          </div> 
         <div class="wrapper"> 
          <div class="floatleft"> 
           <label id="lblState"> 
           <span class="bg"><input id="State" name="State" type="text" value="" placeholder="State:" class="input"></span> 
           <span class="error">*This is not a valid URL.</span> <span class="empty">*This field is required.</span> </label></div> 
          <div class="floatleft"> 
           <label id="lblPostalCode"> 
           <span class="bg"><input id="PostalCode" name="PostalCode" type="text" value="" placeholder="PostalCode:" class="input"></span></label></div> 
          <div class="floatleft"> 
           <label id="lblCountry"> 
           <span class="bg"><input id="Country" name="Country" type="text" value="" placeholder="Country:" class="input"></span></label></div> 
         </div> 
        </div> 
       </div> 
       <div id="showright"> 
        <div id="messages"> 
         <h3>Billing Options</h3> 
         <div class="wrapper"> 
          <input type="radio" name="radio" id="PayWPayPal" value="PayWPayPal"><label for="PayWPayPal">Pay using PayPal Balance</label> 
          <br /> 
          <input type="radio" name="radio" id="PayWCC" value="PayWPayPal"><label for="PayWCC">Pay using Credit Card</label> 
         </div> 
         <div id="CCFields"> 
          <div class="wrapper"> 
           <div class="floatleft"> 
            <label id="lblCCType"> 
             <span class="bg"><select> 
              <option value="Visa">Visa</option> 
              <option value="Mastercard">Mastercard</option> 
              <option value="Amex">Amex</option> 
              <option value="Discover">Discover</option> 
             </select></span> </label></div> 
           <div class="floatleft"> 
            <label id="lblCCNum"> 
            <span class="bg"><input id="CCNum" name="CCNum" type="text" value="" placeholder="xxxx xxxx xxxx xxxx" class="input"></span> </label></div> 
          </div> 
          <div class="wrapper"> 
           <div class="floatleft"> 
            <label id="lblCCExpiration"> 
            <span class="bg"><input id="CCExpiration" name="CCExpiration" type="text" value="" placeholder="MM/YY" class="input"></span></label></div> 
           <div class="floatleft"> 
            <label id="lblCVV"> 
            <span class="bg"><input id="CVV" name="CVV" type="text" value="" placeholder="CVV" class="input"></span></label></div> 
          </div> 
         </div> 
        </div> 
        <div class="wrapper"> 
          <div class="btns"><strong><input name="Pay" type="submit" class="button1" value="Confirm Quantities and Pay"></strong></div> 
        </div> 
       </fieldset> 
      </form> 
      </div> 
     </li> 
    </ul> 
</article> 
</div> 
</body> 
</html> 

而CSS:

a, abbr, acronym, address, applet, article, aside, audio, 
b, blockquote, big, body, 
center, canvas, caption, cite, code, command, 
datalist, dd, del, details, dfn, dl, div, dt, 
em, embed, 
fieldset, figcaption, figure, font, footer, form, 
h1, h2, h3, h4, h5, h6, header, hgroup, html, 
i, iframe, img, ins, 
kbd, keygen,label, legend, li, meter, nav, 
object, ol, output, p, pre, progress, 
q, s, samp, section, small, span, source, strike, strong, sub, sup, 
table, tbody, tfoot, thead, th, tr, tdvideo, tt, u, ul, 
var{ 
background: transparent; 
border: 0 none; 
font-size: 100%; 
margin: 0; 
    padding: 0; 
    border: 0; 
    outline: 0; 
vertical-align: top; } 

ol, ul { 
list-style: none; 
} 
* { border:none} 

article, aside, audio, canvas, command, datalist, details, embed, figcaption, figure, footer, header, hgroup, keygen, meter, nav, output, progress, section, source, video{ display: block; } 
mark, rp, rt, ruby, summary, time{ display: inline } 

.left { float:left;} 
.right { float:right;} 
.wrapper {width:100%; overflow:hidden;} 
.relative{ position:relative;} 

body{ background: url(../images/bg.gif) center top repeat #100f10; border:0; font:13px Arial, Helvetica, sans-serif; color:#717171; line-height:22px; min-width:960px; overflow:hidden} 
.container_24 { 
margin-left: auto; 
margin-right: auto; 
width: 1260px; 
height:50px; 
} 
h2{ font-size:25px; color:#26251e; line-height:1.2em; padding: 0 0 27px 0; letter-spacing:-1px;} 
.grid_6, 
.grid_24 { 
display:inline; 
float: left; 
position: relative; 
margin-left: 5px; 
margin-right: 5px; 
} 
.container_24 .prefix_1 { 
padding-left:40px; 
} 
.floatleft { 
width: 260px; 
float: left; 
margin: 5px; 
} 
.floatright { 
float: right; 
margin: 5px; 
} 
#showright { 
float:right; 
width:390px; 
margin:2px; 
position:relative; 
} 
.baseform { 
width:850px; 
float:left; 
} 
#messages { 
height:200px; 
margin:100px 30px; 
} 
#information { 
z-index:9; 
background-color:#FFFF99; 
height:200px; 
width:200px; 
position:absolute; 
display:none; 
} 
#content > ul{ margin:0 7px 0 5px; position:relative; margin-top:0px; z-index:1;} 
#content > ul > li{ background:#fafafa; height:556px; width:100%; padding-top:60px; position:relative;} 
.label { margin:0; width:320px; height:17px; background:#CCC; padding:6px 12px;color:#717171; font:13px Arial, Helvetica, sans-serif;} 
.line2{ background:url(../images/line_vert1.gif) 845px 0 repeat-y;} 
#GenericForm{ padding-top:7px; position:relative;} 
#GenericForm .wrapper{ overflow:inherit; min-height:37px; width:900px;} 
#GenericForm .success{ padding:15px 30px; display:none; background:#26251e; color:#fff; top:150px; left:0; right:0; position: absolute; z-index:2} 
#GenericForm label{ position:relative;min-height:31px; display: inline-block; z-index:1;} 
#GenericForm .message{ height:250px;} 
#GenericForm span{ display:block} 
#GenericForm .error, #GenericForm .empty{ font-size:10px; color:#26251e; line-height:14px; display:none; width:100%} 
#GenericForm a{ margin-right:15px; float: left; width:63px; text-align:center} 
#GenericForm .input { margin:0;width:204px; height:17px; background: none; padding:6px 12px;color:#717171; font:13px Arial, Helvetica, sans-serif;} 
#GenericForm .inputoptional { margin:0;width:204px; height:17px; background: #FFC; padding:6px 12px;color:#717171; font:13px Arial, Helvetica, sans-serif;} 
#GenericForm textarea { overflow: auto; margin:0;width:204px; height:258px; background: none; padding:7px 12px;color:#717171; font:13px Arial, Helvetica, sans-serif;} 
#GenericForm .bg{ background:#f2f2f2; border:1px solid #fff; border-top:1px solid #c4c4c4; border-left:1px solid #c4c4c4; float:left;} 
.button1{ display:inline-block; font-size:12px; color:#fff; text-transform:uppercase; line-height:33px; position:relative; background:#393436;} 
.button1:hover{ color:#FF9} 
.button1 span{ position: absolute; top:0; left:0; width:100%; height:100%; background:#e54d26} 
.button1 strong{ position:relative; padding:0 11px;} 

那麼,如何解決這一問題?我正在使用的佈局有什麼問題嗎? 請注意,實際的頁面更復雜(並在PHP中),我已經提取了一些來證明問題。

+0

很多工作,但是表格裏面的所有div都應該改爲span,並且相應地編輯CSS。 –

+0

絕對從驗證HTML開始。 [W3 HTML驗證器](https://validator.w3.org/) – shamsup

+0

我驗證了代碼(使用相同的鏈接)並驗證正確。 – Chiwda

回答

3

問題:

它是非法的語法它的子元素被關閉之前關閉父元素。使用HTML時,始終遵循LOFC(上次首次公開封閉)方法很重要。

解決辦法:

充分利用<form>元素的父,而不是申報單。將幾乎所有的元素放在表單元素中是完全正確的。

+0

「在其子元素關閉之前關閉父元素的非法語法」,但是它適用於非樣式元素嗎? – Chiwda

+0

它適用於所有元素。搜索「格式良好的HTML元素」以獲取更多信息。從技術上講,沒有風格與非風格元素(至少自CSS以來)。 HTML元素定義了文檔的結構,並且每個元素都有一個默認樣式,它最終是用於定義文檔樣式的CSS。另外,你曾經提到你的代碼在驗證器中工作正常。由於您的代碼格式不正確,它會導致驗證程序失敗。我只是將你的HTML代碼粘貼到W3驗證器中,它出現了5個錯誤。 – kojow7

+0

嗯,我可能已經發布了臨時代碼,但通過表單元素拆分div,W3驗證器通過了它。但是,Firefox查看源確實以紅色突出顯示了表單和字段集標籤。 – Chiwda