I think it'd be great to add a class to the body element that's based on the current width of the page/screen.
For example, if the page/screen width is 1280px, add 'screen-large' as a class to the body. Or if the width is 800px, add 'screen-small' to the body.

This way, people can theme their pages differently based on the current width of the page/screen.
For example:

body.screen-large #sidebar-left {
  width: 300px;
}

body.screen-small #sidebar-left {
  width: 150px;
}

I got the idea from this article on A List Apart, and modified the code to produce the attached .js file.
It just needs to be loaded to work.

I thought about making this a module, then people could easily specify their own class names and widths from the UI, but I'm not a module developer yet, so thought it might be better as part of the Zen theme for now...
Let me know what you think.

CommentFileSizeAuthor
class-width.js_.txt1.42 KBAnonymous (not verified)

Comments

SeanBannister’s picture

I like the idea however I'm not sure if it's really practical. According to w3schools as of January 2008 5% of users had no javascript enabled so you would need this to downgrade gracefully by specifying a default size in the body tag of the page.tpl.php.

I think if a developer is going to the trouble of creating css for multiple resolutions then they should add this functionality to their theme, but I don't think it should be a default part of Zen. I'd like to hear what other people think however and some good use cases.

Anonymous’s picture

I like the idea however I'm not sure if it's really practical. According to w3schools as of January 2008 5% of users had no javascript enabled so you would need this to downgrade gracefully by specifying a default size in the body tag of the page.tpl.php.

If javascript isn't enabled, the body element won't get that additional class added to it. In this case, the page is styled as per the default CSS (see code below). It's obviously up to the developer how they use the additional class, but I figure you develop the normal CSS to suit most people, then use the additional class to modify the design for certain groups of people (i.e. those with small monitors):

#sidebar-left {
  width: 200px;
}

body.screen-small #sidebar-left {
  width: 100px;
}

As long as you design a default theme that doesn't rely on the additional classes, it's fully non-javascript compatible. No default body size tags needed.

I think if a developer is going to the trouble of creating css for multiple resolutions then they should add this functionality to their theme, but I don't think it should be a default part of Zen. I'd like to hear what other people think however and some good use cases.

As previously stated, I originally thought this'd make a good module, but since I can't develop modules yet, I stuck with making this a code/patch. Obviously it'd be great if all developers added it to their themes, but I needed a place to start, so thought I'd try Zen (since it's purpose is helping people create custom themes).

As for a use case, regardless of whether this is added to Zen or not, I'll be using it on a site I'm developing.
The site is made to display 2 sidebars (left and right) and a content area in-between. The sidebars are fixed widths, while the content area is fluid and the whole page width is 100%. One main part of the site will divide the content area into two columns: the main content on the left and supplementary content and images on the right, but still between the two sidebars. When viewed on my 1280x1024 monitor, everything looks fine, but when it's viewed on an 800x600 screen, the main content area is very small, let alone when you view a page with the two middle columns.
Therefore, I would use the additional body class to make the right sidebar display underneath the left sidebar when my site is viewed at 800x600 or smaller.

The idea isn't that you develop new styles for each different size, but use the ones you need. They're just there to help.

Hope I've helped explain this a bit better :)

SeanBannister’s picture

Yeah I totally understand and see that it would be useful but I'm still not sure if it should be in Zen, I'm heading towards this being a separate module.

If you'd like to learn how to create modules there's the module developer guide http://drupal.org/node/508

Anonymous’s picture

Thanks for your feedback Sean.

I've actually ordered Matt Butcher's "Learning Drupal 6 Module Development" book from Amazon :)
Maybe this'll be the first module I develop...

yoroy’s picture

Status: Needs review » Closed (won't fix)

I agree this should not be made part of Zen itself. Would be nice to hear if you manage to get the module working!

autopoietic’s picture

Really great book - makes it all seem straight forward, got me interested anyway

krabbe’s picture

Title: Add class to body based on current page width » Great idea for using different header-graphics

It would be great to have this function for themes with 100%-width header-images, so they could be changed depending on actual width of the browser-window.
I saw something like that on a wordpress-theme, but I don't remember which one it was.

Anonymous’s picture

Title: Great idea for using different header-graphics » Add class to body based on current page width

Reverting title...