Home arrow Style Sheets arrow Page 3 - Swapping Column Positions in Web Page Layouts with Negative Margins
STYLE SHEETS

Swapping Column Positions in Web Page Layouts with Negative Margins


In this second part of a four-part series on using negative margins to create DIV-based web page layouts, we're going to expand on what we learned in the first article by actually switching the positions of the columns of our sample web page. Keep reading to learn how.

Author Info:
By: Alejandro Gervasio
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
August 26, 2008
TABLE OF CONTENTS:
  1. · Swapping Column Positions in Web Page Layouts with Negative Margins
  2. · Review: using negative margins to build a two-column liquid design
  3. · Swapping the position of web page columns
  4. · The complete source code for the previous two-column liquid design

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Swapping Column Positions in Web Page Layouts with Negative Margins - Swapping the position of web page columns
(Page 3 of 4 )

As I stated in the section that you just read, a two-column web page layout like the one created previously can be easily modified to swap the positions of its respective columns. In other words, the consequence in doing this would be that the corresponding side bar now would be placed on the left of the web document, and the main column obviously would be floated to the right.

Of course, to construct this brand new layout I’m going to use the handy negative margin approach, so the CSS styles corresponding to this example now look like this:

/* style header section */

#header{

background: #ffc;

}

/* style side column */

#sidecol{

float: left;

width: 300px;

background: #eee;

}

/* wraps up the main column */

#wrapper{

width: 100%;

float: right;

margin-left: -300px;

}

/* style main column */

#maincol{

margin-left: 300px;

}

/* style footer section */

#footer{

clear: both;

background: #ffc;

}


That was pretty simple to understand, wasn’t it? As you can see, since my intention was simply to revert the positions of the main and side columns within the pertinent web document, I specified a negative value of –300 px for the wrapper of the main column, which also has been floated to the right. On the other hand, the side bar has been floated to the left, swapping the positions between these containing elements.

In addition, the rest of the CSS styles listed above are responsible for styling the respective header and footer section of the web page, so I won’t bore you with irrelevant explanations about how they work.

Well, at this moment, you have learned how to use the functionality of CSS negative margins to invert the respective positions of the two primary columns within a sample web page. As you probably realized, this process is a no-brainer and can be tackled with minor problems.

However, undoubtedly the missing piece of this schema is the structural markup that’s tied to the CSS styles coded earlier. Taking this into account, therefore, in the section to come I’m going to show you the full source code of this two-column web page layout, whose respective main columns have been swapped.

Don’t waste more time; read the next few lines. I’ll be there, waiting for you.


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials