Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Headings with classes?

Featured Replies

When I have never needed to do something before logical thinking seems a bit out there and a question form in my mind 'is it really possible to do what I think is possible' As such I need a little yes or no question answered.

 

Is it possible to set headings up so they have a class?

 

I need two sets of headings for a site I am doing, and have never really needed to do this before so I was wondering if I set a class in the body would I then be able to set headings to go with that class. Something like this:

 

CSS:

 

.bod_one, bod_two {
background: #e1e1e1;
/*-some other things too more than likely :p -*/ 
}

.bod_one h1 {
/*-stuff here*/ 

.bod_two h1 {
/*-some different stuff here-*/

 

Then call the class in the body like so:

 

<body class="bod_one">
<h1>La La La</h1>

 

would it pick up on the different headings? I have tested it and it does seem to work so my logic is somewhat there, but I was only able to test on IE7 and FF as they are the only browsers on the computer that I am on...so would this downgrade to IE6 for example or work in other browsers?

 

It seems logical that it would work, but a little voice tells me that its not going to, so its best to ask :p

Dizi, might be worth adding the class to the H1 itself rather than the body. Some browsers get a bit fussy about body classes.

  • Author

there will be more than just the h1 tag though and so I was looking for a way to do it so it could just be <h1><h2><h3> ..ect rather than <h1 class="something"><h2 class="something else"><h3 class="something more">. But if its not going to work in all browsers then I guess I will have to do it that way, rather than something I thought would make it easier :mellow:

  • Author

If anyone has had experience doing it the way I explained and knows it will work in IE6 + and other browsers without causing confusion let me know :) As I really can't see why it can't work this way but need to know if I am right in my logical illogical thinking :p

If you're only applying this to the body element, why are you using classes and not an id?

  • Author

:rolleyes: Ok then fine...

 

Would my idea for the headings work across all browsers if I added an id to the body and then styled my different headings to that that id as well? So that I can just use <h1></h1<h2></h2> and they would pick up the style for just that ID and not the other one? ;)

Yes if you set a body id, or indeed an id for the elements parent div you can do this..

 

Using the body tag only...

 

<body id="home">
<h1>Page title</h1>
<h2>Sub title</h2>
</body>

#home h1 {
my styles
}
#home h2 {
my styles
}

 

But what if you want to make an exception, lets say your subheading is wrapped in it's own div with another id? The answer is to define a rule for the other id...

 

<body id="home">
<h1>Page title</h1>
<div id="section">
<h2>Sub title</h2>
</div>
</body>

#home h1 {
my styles
}
#home h2 {
my styles
}
#section h2 {
my styles
}

  • Author

I am running my idea through browsershoot.org to test it on as many browsers as possible :) As I now know it will work on IE6+7 and firefox, so now just all the other ones need tested :p

 

But thanks bluedreamer its nice to know that my sort of logic was right and I could do it that way...id or class :p

lol sorry about being anal dizi, just thought it worth a mention in case body responded more consistently to id than class, or something like that...... :lol:

 

p.s. - glad to see someone still concerned with ie6, and not just righting the ie6 users off.

  • Author

no worries, I had just been working with classes all day that when I thought about it, class was the first thing that popped into my mind :p

I use ID's for the BODY of my pages so I can address styles on spesific pages. I've not had any problems with any browsers doing this. Not even the old IEs.

  • Author

Thanks thomas :)

 

I have just looked at the screenshots on browsershoot.org and it has shown it works on all the browsers I tested for even ie5 so that's always a plus :p

 

 

 

Thanks for the help everyone :D

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.