2012-07-01 163 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