15 Adjust margins in Blogger templates
August 01, 2007 /

In Blogger templates, margins define the space between elements of the blog, such as the space between the main posts section and the sidebar. If you have added a second sidebar, or simply wish to alter the layout of your blog, you may wish to change some of the margin specifications for elements of your template. In this post, I'll explain how this can be achieved, with examples to help you understand what can be done.

The margins of each blog element (ie: header, sidebar, main-section) are specified in the "Style" section of your Blogger template:

  • In the "new" Blogger layouts templates, the style is specified between the <b:skin> and </b:skin> tags
  • In "Classic" Blogger templates, the styles are specified between the <style> and </style> tags
For both types of Blogger templates, margins can be defined in the same ways.

The best way for me to explain how margins work is by using an example; here is the style element for my right sidebar as it appears in my blog template:

#sidebar-wrapper {
margin: 0 14px 0 10px;
width: 240px;
float: right;
background-color: $mainBgColor;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
We need to focus on the red line, which specifies the margins (the space surrounding) the sidebar element. As you can see, there are four margins specified in this one line; these are defined in the following order:
  1. Top margin: 0
  2. Right margin: 14px
  3. Bottom margin: 0
  4. Left margin: 10px
I can increase or decrease these margins by altering the number associated with each margin. For example, if I wanted to define a space of 10 pixels between the header section and the top of the sidebar, I would change this line as follows:
margin: 10px 14px 0 10px;
Sides which do not have a margion should be specified as "0"; those for which you would like a margin can have this specified in pixels (eg: 10px), or in other CSS units (which you can read about here). In most Blogger templates, margins are specified as pixels.

If you prefer all margins surrounding an element to be equal, you can define this using only one statement, eg:

margin: 15px;
This ensures that the margins of the top, right, bottom and left of an element are all 15 pixels wide.

One final method of defining margins is to specify the margin in the description, eg:
margin-top: 15px; margin-right: 10px; margin-bottom: 5px; margin-left: 0;
Here are some examples of the spaces which can be created using margins in the style of a template: Header section has margins defined as "15px 15px 10px 15px.

Now the main-element has a margin-left definition of 15px...

... and finally, the "sidebar" element has margins defined as: 20px 0 0 40px; (in addition to the margins of the other elements).

A great way to experiment with margins is to use the "Try it Editor" featured over at W3 Schools. Here you can adjust the margins in the left hand pane and see the results imedietly in the right section: By default, the code does not feature DIV elements as you would find in Blogger templates, so you may like to copy and paste the following code into the left window in order to experiment in the same way I have described:

<html>
<head>
<style type="text/css">
.outer-wrapper {width:400px; height:200px; border:2px solid; border-color:#f00;}
.header {width:300; border:1px solid; margin: 15px 15px 10px 15px; float: left;}
.main {float:left; width:150; height:100px; border:1px solid; margin-left: 15px;}
.right {float:left; width:100; height:100px; border:1px solid; margin: 20px 0 0 40px;}
</style>
</head>
<body>
<div class="outer-wrapper">
<div class="header">Header section</div>
<div id="main-wrapper">
<div class="main">Main section</div>
<div class="right">Sidebar section</div>
</div>
</div>
</body>
</html>

Have fun experimenting with the margins of your Blogger template! Don't forget, you can always play around with the margins and preview the changes before saving. To be on the safe side, it's always good practise to make a backup of your template before altering it.

Technorati Tags: | | | |

15 Comments:

30 May 2008 01:30 Alan said...
This post has been removed by the author.
2 June 2008 01:11 Alan Bamboo said...

Hi Amanda,

I'm very new at HTML, learning it as I go, mostly with you...

I like this post as it has some diagrams.
I finally figured out header and how to move it this weekend etc.

I just figured out that wrappers are below the header...I thought wrappers were like borders or something. I kept trying to figure out how to move the contents in the main body...and get looking in the html for main section lol.

Diagrams for a newb are good.

21 June 2008 04:23 CrochetQueen said...

I cannot get a space between my sidebar and post section. Any thoughts?

10 August 2008 15:11 ed said...

Hi Amanda, don't mind if you can help me out here, Firstly, I am stumped at trying to reduce the spaces between vertical pictures on my sidebar and a technorati icon. (the space between is the title which i leave blank)

Also, I wonder how do you set up those buttons on your side bar, the 3 side by side and the row of little buttons. Is there a tutorial?

14 September 2008 06:08 Myk bLAuuw! said...

Hello Amanda, I'm a big fan of the blog,,,you've been able to answer pretty much all of my questions...


I'm still having one problem with my 3 columns (which I learned how to do from you haha).


I know it's probably an easy problem to fix, but I can't seem to figure it out reading through different guide's & how-to's.

There is too much space to the left of my left column, & not enough space to the right of my right column.

I would like all 3 columns to have equal space on the screen (with a little space on each side of the far left & far right column & a small space between the left/right column & middle column).


If you could take a look @ my blog & let me know what my problem is/how to go about fixing it, I would be extremely grateful.

Thanks a lot.

23 September 2008 23:49 MissandMisterKinkY said...
This post has been removed by the author.
16 October 2008 01:08 Ms Unreliable said...

This is probably going to be the stupidest question ever, but my Blogger template squishes the posts together and I'd like to change the default spacing between posts in the main section of the blog. How do I do this? Is it as simple as finding the right bit of code and changing the margins? If so, which bit of code? :D Thanks!

16 October 2008 12:59 Blood Roses said...

Hi,
I have the same problem as Myk bLAuuw! i think...my sidebr and mian text are too close together (like the left and right margins are too big) - currently it is this:

http://thebloodroses.blogspot.com/

but i want the margins to be like this:

http://knighttcat.blogspot.com/

if you have any ideas as to how i can achieve that spacing, it would be much appreciated! :)

15 November 2008 05:54 Martí Broquetas said...
This post has been removed by the author.
13 January 2009 22:22 "Evelle" said...

Hi, I have a slightly different question: How can I adjust the space of my text? I tried margins, but that just moves the whole grey box, never the text inside the grey box. I want to move it away from the black frame. Where should I change something to adjust the margin on the left side of the text?

http://evelle26.blogspot.com/


Thanks a lot!

26 June 2009 01:10 Bree said...

Hi Amanda,

I, like crochet queen, cannot get a space between my sidebar and post section, creating a cluttered look on my blog. Any help would be appreciated. Thanks!

6 July 2009 21:02 Jesse said...

Thanks for the info!

23 August 2009 21:30 July's junk said...

Hi! I'm really new to this and get spontaneously lobotomized as soon as I have to figure something new out slightly related to the subject of computers and similar technical issues.. Anyways, I cannot get over the fact that my blog (not a really serious one, but with the current amount of knowledge it will never be) has such a narrow main area, resulting in all my pictures being cut off on the right side!

I would be sooo greatful if some mercyful soul would hand a fairly pedagogic explanation on how I should adress the to me rather frustrating matter!

Thanks in advance!

4 March 2010 19:45 raina said...

I have the same problem as many of you. I need more space between my main section and my sidebar. When I put up pictures in the main area to the size I would like they are cut off by the side bar. I tried to follow your directions but don't seem to have the same code as you show.
This is what it looks like-#sidebar-wrapper {
width: 250px;
float: $endSide;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
I also have another question that perhaps you can answer. I have a great shade of orange for the text on my sidebar, but when I try to match it in my main body text the choice of shades are different. Is there any way to match the shade I prefer to be able to use it in the main body text?
Thanks, Raina

Post a Comment

Browse through the Archives

All existing posts are still available to view while I'm working on the site, albeit seen in a much simpler interface. Feel free to browse through the archives to find tutorials, templates and articles to help you build a better blog:

Blog Archive

© Blogger Buster 2010 Home | About | Contact | Hire Me