Add class to body based on current page width

Created on 17 October 2008, about 16 years ago
Updated 16 May 2024, 7 months ago

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.

Feature request
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024