2012-07-01 162 views
0

這是一個非常簡單的問題。我有一些示例代碼,並試圖圍繞CSS如何工作。如何在CSS中將側邊欄移動到右側?

這裏是我的html文件:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Widget Corp</title> 
     <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" /> 
    </head> 
    <body> 
     <div id ="header"> 
      <h1>Widget Corp</h1> 
     </div> 
     <div id ="main"> 
      <table id="structure"> 
       <tr> 
        <td id="navigation"> 
         &nbsp; 
        </td> 
        <td id="page"> 
         <h2>Staff Menu</h2> 
         <p>Welcome to the staff area.</p> 
         <ul> 
          <li><a href="content.php">Manage Website Content</a></li> 
          <li><a href="new_user.php">Add Staff User</a></li> 
          <li><a href="logout.php">Logout</a></li> 
         </ul> 
        </td> 
       </tr> 
      </table> 
     </div> 
     <div id="footer">Copyright 2012, FlameDra</div> 
    </body> 
</html> 

這裏是我的CSS文件:

html { height : 100%; width : 100%;} 
body { height : 100%; width : 100%; margin : 0px; padding : 0px; border : 0px; 
     font-family: Verdana, Arial, Helvetica, sans-seriff; background: #D4E6F4; 
     font-size : 13px; line-height: 15px; } 
img { border: none;} 
table, tr, td { border-collapse : collapse; vertical-align : top; font-size : 13px; 
       line-height: 15px; } 
a { color: #8D0D19;} 

#header { height: 70px; margin: 0px; padding: 0px; text-align: left; 
      background: #1A446C; color: #D4E6F4; } 
#header h1 { padding: 1em; margin: 0px;} 
#main {margin: 0px; padding: 0px; height: 600px; width: 100%; background: #EEE4B9; } 
#structure {height: 600px; width: 100%;} 
#footer {height: 2em; margin: 0px; padding: 1em; text-align: center; background: #1A446C; color: #D4E6F4; } 

/* Navigation */ 
#navigation { width: 150px; padding: 1em 2em; color: #D4E6F4; background: #8D0D19;} 
#navigation a {color: #D4E6F4; text-decoration: none;} 
ul.subjects {padding-left: 0; list-style: none;} 
ul.pages {padding-left: 2em; list-style: square;} 
.selected {font-weight: bold;} 

/* Page Content */ 
#page {padding-left: 2em; vertical-align: top; background: #EEE4B9;} 
#page h2 {color: #8D0D19; margin-top: 1em;} 
#page h3 {color: #8D0D19;} 

這是輸出的樣子:http://i.imgur.com/x9Sn3.jpg

現在我有麻煩了解側邊欄如何顯示在左側,而不是右側,因爲通過查看代碼,我無法確切知道其定義的位置。

難道有人只是用這個例子來說明'CSS如何工作'有點清晰?

+0

它在CSS沒有定義。它在HTML本身中定義。 –

回答

3

簡單,只需更換:

<td id="navigation"> 
    &nbsp; 
</td> 
<td id="page"> 
    <h2>Staff Menu</h2> 
    <p>Welcome to the staff area.</p> 
    <ul> 
     <li><a href="content.php">Manage Website Content</a></li> 
     <li><a href="new_user.php">Add Staff User</a></li> 
     <li><a href="logout.php">Logout</a></li> 
    </ul> 
</td> 

隨着

<td id="page"> 
    <h2>Staff Menu</h2> 
    <p>Welcome to the staff area.</p> 
    <ul> 
     <li><a href="content.php">Manage Website Content</a></li> 
     <li><a href="new_user.php">Add Staff User</a></li> 
     <li><a href="logout.php">Logout</a></li> 
    </ul> 
</td> 
<td id="navigation"> 
    &nbsp; 
</td> 
+0

這個答案當然是正確的,但對於如何更好地構建這類頁面的想法,請參閱http://www.webdevout.net/test?0c&raw http://dpaste.com/766156/plain/ 。 – reisio

+0

所以只需將它移動到下方,它會顯示在左側? – FlameDra

+0

@ FlameDra:是的 - 從左到右和從上到下,這是HTML的普通順序。 – reisio