FlameDra
FlameDra

Reputation: 2087

How to move sidebar to right in CSS?

Its a pretty simple problem. I have some sample code and am trying to wrap my head around how CSS works.

Here is my html file :

    <!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>

And here is my CSS file :

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;}

This is what the output looks like : https://i.sstatic.net/kwOVU.jpg

Now I'm having trouble understanding how the sidebar appears on the left side, instead of the right, since by looking at the code I can't really tell where its been defined.

Could someone just use this example to make 'how CSS works' a bit clearer?

Upvotes: 0

Views: 2583

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167250

Simple, just replace:

<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>

With

<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>

Upvotes: 3

Related Questions