2017-05-07 42 views
3

我正在嘗試使id =「contact_details」的部分出現在id =「form」旁邊。它適用於我的一個CSS樣式表,但不適用於其他樣式表。我不知道我要去哪裏錯了......我試過它,沒有相對位置,不同寬度等。爲什麼我的「float:left;」不行?

您的幫助將非常感謝!歡呼聲中,瑪麗

#wrapper { 
 
    width: 989px; 
 
    margin: 0 auto 0; 
 
    position: relative; 
 
    background-color: gray; 
 
    } 
 

 
    #contact_details { 
 
    float: left; 
 
    position: relative; 
 
    width: 350px; 
 
    padding-top: 30px; 
 
    padding-left: 30px; 
 
    padding-right: 30px; 
 
    background-color: blue; 
 
    } 
 

 
    #form { 
 
    float: left; 
 
    position: relative; 
 
    width: 450px; 
 
    padding-top: 30px; 
 
    padding-right: 30px; 
 
    background-color: red; 
 
    } 
 

 
    #form_table { 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    }
<body> 
 
    <div id="wrapper"> 
 
    <header></header> 
 
    <nav></nav> 
 
    <section id="contact_details"> 
 
     <h1>Contact Details</h1> 
 
     <br> 
 
     <h3>Physical Address</h3> 
 
     <p><em>There and Back Travel</em></p> 
 
     <p>Travel House Level 1</p> 
 
     <p>Travel Line North</p> 
 
     <p>Waikanae</p> 
 
     <p>New Zealand</p> 
 
    </section> 
 
      
 
    <aside id="form"> 
 
     <h1></h1> 
 
     <form name="user_details"> 
 
     <table id="form_table"> 
 
      <tr> 
 
       <td class="form_cell"><label for="first_name">First Name:</label></td> 
 
       <td class="form_cell"><input type="text" name="first_name"></td> 
 
      </tr> 
 
      <tr> 
 
       <td class="form_cell"><label for="surname">Surname:</label></td> 
 
       <td class="form_cell"><input type="text" name="surname"></td> 
 
      </tr> 
 
      <tr> 
 
       <td>Preferred tour types:</td> 
 
       <td> 
 
        <input type="checkbox" name="adventure">Adventure<br> 
 
        <input type="checkbox" name="beach">Beach<br> 
 
        <input type="checkbox" name="leisure">Leisure<br> 
 
       </td> 
 
      </tr> 
 
     </table> 
 
      <input type="submit"><input type=reset> 
 
     </form> 
 
    </aside> 
 
      
 
    <footer></footer> 
 
    </div> 
 
    </body> 
 

+1

請運行您的代碼段,你會看到它工作得很好。 –

回答

1

它看起來正確的... enter image description here

如果在其他樣式表文件把這段代碼有一個非常好的機會了這個樣式表文件將被加載在其他樣式表文件之前,然後那些在之後加載的文件有一些規則覆蓋了您的文章中的規則。 查看樣式表如何加載的順序。基本上,最後一條規則將決定元素在屏幕上的顯示方式。

#wrapper { 
    display: block; 
} 
#wrapper { 
    display: none; 
} 

#wrapper元件將不被顯示,因爲最後一個規則的。 注意:有一種方法可以通過使用!important來實現上述規則的工作,但這不是建議的做法。

2

它的工作原理,只要確保您正確加載樣式表,並提供一個有效的HTML骨架。

我已經改變的#contact_details浮子屬性right,以確保旁#form元件出現#contact-details塊。

以下是您的代碼的一些細微更改。 Screenshot: Markups result

<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <meta charset="utf-8"> 
 
\t \t <title></title> 
 

 
\t \t <style type="text/css"> 
 
\t \t \t #wrapper { 
 
\t \t \t \t width: 989px; 
 
\t \t \t \t margin: 0 auto 0; 
 
\t \t \t \t position: relative; 
 
\t \t \t \t background-color: gray; 
 
\t \t \t } 
 

 
\t \t \t #contact_details { 
 
\t \t \t \t float: right; 
 
\t \t \t \t position: relative; 
 
\t \t \t \t width: 350px; 
 
\t \t \t \t padding-top: 30px; 
 
\t \t \t \t padding-left: 30px; 
 
\t \t \t \t padding-right: 30px; 
 
\t \t \t \t background-color: blue; 
 
\t \t \t } 
 

 
\t \t \t #form { 
 
\t \t \t \t float: left; 
 
\t \t \t \t position: relative; 
 
\t \t \t \t width: 450px; 
 
\t \t \t \t padding-top: 30px; 
 
\t \t \t \t padding-right: 30px; 
 
\t \t \t \t background-color: red; 
 
\t \t \t } 
 

 
\t \t \t #form_table { 
 
\t \t \t \t padding-left: 0px; 
 
\t \t \t \t padding-right: 0px; 
 
\t \t \t } 
 
\t \t </style> 
 
\t </head> 
 
\t <body> 
 
\t \t <div id="wrapper"> 
 
\t \t \t <header></header> 
 
\t \t \t <nav></nav> 
 

 
\t \t \t <section id="contact_details"> 
 
\t \t \t  <h1>Contact Details</h1> 
 
\t \t \t  <br> 
 
\t \t \t  <h3>Physical Address</h3> 
 
\t \t \t  <p><em>There and Back Travel</em></p> 
 
\t \t \t  <p>Travel House Level 1</p> 
 
\t \t \t  <p>Travel Line North</p> 
 
\t \t \t  <p>Waikanae</p> 
 
\t \t \t  <p>New Zealand</p> 
 
\t \t \t </section> 
 

 
\t \t \t <aside id="form"> 
 
\t \t \t  <h1></h1> 
 
\t \t \t  <form name="user_details"> 
 
\t \t \t  <table id="form_table"> 
 
\t \t \t   <tr> 
 
\t \t \t    <td class="form_cell"><label for="first_name">First Name:</label></td> 
 
\t \t \t    <td class="form_cell"><input type="text" name="first_name"></td> 
 
\t \t \t   </tr> 
 
\t \t \t   <tr> 
 
\t \t \t    <td class="form_cell"><label for="surname">Surname:</label></td> 
 
\t \t \t    <td class="form_cell"><input type="text" name="surname"></td> 
 
\t \t \t   </tr> 
 
\t \t \t   <tr> 
 
\t \t \t    <td>Preferred tour types:</td> 
 
\t \t \t    <td> 
 
\t \t \t     <input type="checkbox" name="adventure">Adventure<br> 
 
\t \t \t     <input type="checkbox" name="beach">Beach<br> 
 
\t \t \t     <input type="checkbox" name="leisure">Leisure<br> 
 
\t \t \t    </td> 
 
\t \t \t   </tr> 
 
\t \t \t  </table> 
 
\t \t \t   <input type="submit"><input type=reset> 
 
\t \t \t  </form> 
 
\t \t \t </aside> 
 

 
\t \t \t <footer></footer> 
 
\t \t </div> 
 
\t </body> 
 
</html>

相關問題