Crafting CSS style sheet

This is the most time consuming operation in porting any CSS template to BlogEngine. If you like your design pixel perfect - that will cost you. These are some general tips that I hope will help make job a little bit easier.

  • Move forward gradually, addressing one area at a time. Make sure your header section looks right and only then go to the post, comments, sidebar, archive etc. You don't want to go though the changes you've made in the last couple hours looking for one that totally screwed page layout or changed that color you really liked.
  • Each step verify at least in Firefox and IE. Throwing into the mix Opera and Safari would be nice, too.
  • Get a tool to work with DOM. You want to click on any element on the page and see CSS style attached to it. Firebug or Developer Toolbar will do the job.
  • First, use only style sheet that came with template. Clean it up by removing anything you not going to use. For example, if you going to use only one level in unordered list you don't need "ul li ul li" for this class. Keep it simple.
  • Start with generic html tags like headers, lists, paragraphs, images etc.
  • Once that taken care of, move through BlogEngine style sheet and take only what you'll need. Again, one block at a time and moving on only after checking changes in all browsers you going to support.

Taking advantage of asp.net

BlogEngine is typical asp.net application, you can do in your theme whatever asp.net allows you - and this is a lot!

Add core namespace to the master page to get access to BE objects:

<%@ Import Namespace="BlogEngine.Core" %>

Now you can use it anywhere in the theme if need to. For example, to get a link to home page in any language BE supports:

<a href="<%=Utils.AbsoluteWebRoot %>" rel="home"><%=Resources.labels.home %></a>

It is common for themes to implement menu where current page you are on stands out in some way. You can easily add this by creating small function in code behind that returns different class string for current page:

public string MenuClass(string menuName)
{
  if (Request.Path.Contains(menuName))
    return "class=\"current_page_item\"";
  else
    return "class=\"page_item\"";
}

And then use this function in the theme to get class for the menu element:

<li <%=MenuClass("default.aspx")%> >

If you need to show element on the page only to blogger (admin):

<% if (Page.User.Identity.IsAuthenticated){ %>
    <div>Show admin/blogger content</div>
<%} %>

This tutorial is very basic and meant just to get you started. You can go as far or as little as you wish with your design, implementing sitemap menu, adding content placeholders, user controls and more. The point is, you’ll be really hard pressed to find project that is as easy to theme as BlogEngine. If you don’t like the way your theme looks – go ahead and change it. It is that easy!

Read part one

Test-drive tutorial theme

Download tutorial theme (52.75 kb)

Share/Save/Bookmark
Signature

Comments

9/3/2008 3:06:22 PM #

Chris

Nice tutorial on the back end things dealing with menus and themes... One thing worth mentioning:

You should use the Request.RawUrl syntax instead of Request.Path, like this:

if (Request.RawUrl.Contains(menuName)) {}

So now if you add pages to your menu they will be highlighted as well...

Chris |

10/21/2008 2:25:44 PM #

Ivan | SEO Consultant

I want to add the line of text below the header of the tags page, that reads: ‘Blog Posts Tagged ‘<tag-goes-here>’. Can I do that in the Theme somehow?

Ivan | SEO Consultant |

10/30/2008 5:06:37 PM #

Henrik Stenbæk

Great porting article! WHY haven't I seen this post before today :-0
I’m mostly using Firebug for the work – and it’s also my impression that one can have 70-80% of the theme in place within 2 hours, the remaining parts takes an eternity.

Thanks a lot for the MenuClass() – I need that in all the themes I have ported. And to be earnest: I haven’t been that good in cleaning up the original CSS file for unused content lately – I’m sorry for that one….

Right now I’m struggling finding a way to use different templates (masterpages) for post list and single post view (I need that for porting themes like http://www.cellarheat.com/). I’m trying something like hooking up to the ServingEvent:

BlogEngine.Core.Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);

And then try to change the way the site.master is rendered – but I’m not succeeded in it yet. If you ,or anybody reading this, know a way to do this, please post a hint!

Henrik Stenbæk |

10/30/2008 10:56:41 PM #

rtur.net

If you ,or anybody reading this, know a way to do this, please post a hint!
If you look at my theme, it does look different in single page and list mode. I'm using a trick - if it is single page (e.Location == ServingLocation.SinglePost) I inject additional CSS where set sidebar visibility to false and such. There may be a better way, but it is simple and serves me well...

rtur.net |

11/1/2008 7:35:31 AM #

trackback

Trackback from Onesoft

Yet another BlogEngine 1.4.5.Theme: Angel

Onesoft |

1/8/2009 10:59:00 AM #

Boat Party NYC

Some great tips. I want to create my own blogengine theme. These are good tips to follow when doing custom work as well.

Boat Party NYC |

2/14/2009 6:42:07 AM #

Yachtcharter Griechenland

I was just thinking about Crafting CSS style sheet and you've really helped out. Thanks!

Yachtcharter Griechenland |

3/3/2009 4:43:25 AM #

my little blogs

i actually want to try this kind of theme, i think this is pretty amazing

my little blogs |

3/12/2009 9:14:20 PM #

Pinay My Girl

cool theme.,.i will also try to make my own blogengine theme and thank to the codes.,.

Pinay My Girl |

10/17/2009 10:18:14 PM #

trackback

Lab

Lab

Be.Crssp... Be Creative! |

10/17/2009 10:18:17 PM #

pingback

Pingback from be.crssp.com

Be.Crssp... Be Creative!  | Lab

be.crssp.com |

Comments are closed
<<  March 2010  >>
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Enhanced with Snapshots

Subscribe to Rtur.net