Patrick McElhaney
Patrick McElhaney

Reputation: 59271

YUI Reset CSS Makes <strong><em>this not work</em></strong>

This line in YUI's Reset CSS is causing trouble for me:

address,caption,cite,code,dfn,em,strong,th,var {
    font-style: normal;
    font-weight: normal;
}

It makes my em not italic and my strong not bold. Which is okay. I know how to override that in my own stylesheet.

strong, b 
{
  font-weight: bold;
}

em, i 
{
  font-style: italic;
}

The problem comes in when I have text that's both em and strong.

<strong>This is bold, <em>and this is italic, but not bold</em></strong>

My rule for strong makes it bold, but YUI's rule for em makes it normal again. How do I fix that?

Upvotes: 12

Views: 11699

Answers (10)

travis
travis

Reputation: 36473

I would use this rule to override the YUI reset:

strong, b, strong *, b *
{
  font-weight: bold;
}

em, i, em *, i *
{
  font-style: italic;
}

Upvotes: 7

palmsey
palmsey

Reputation: 5832

If your strong declaration comes after YUI's yours should override it. You can force it like this:

strong, b, strong *, b * { font-weight: bold; }
em, i, em *, i * { font-style: italic; }

If you still support IE7 you'll need to add !important.

strong, b, strong *, b * { font-weight: bold !important; }
em, i, em *, i * { font-style: italic !important; }

This works - see for yourself:

/*YUI styles*/
address,caption,cite,code,dfn,em,strong,th,var {
  font-style: normal;
  font-weight: normal;
}
/*End YUI styles =*/

strong, b, strong *, b * {
  font-weight: bold;
}

em, i, em *, i * {
  font-style: italic;
}
 <strong>Bold</strong> - <em>Italic</em> - <strong>Bold and <em>Italic</em></strong>

Upvotes: 19

alexp206
alexp206

Reputation: 1739

I had a similar problem when I added the YUI Reset to the top of my stock CSS file. I found that the best thing for me was to simply remove all of the

font-weight: normal;

declarations from the YUI Reset. I haven't noticed that this has affected anything "cross-browser."

All my declarations were after the YUI Reset so I'm not sure why they weren't taking affect.

Upvotes: 3

Patrick McElhaney
Patrick McElhaney

Reputation: 59271

I thought I had an ideal solution:

strong, b 
{
  font-weight: bold;
  font-style: inherit;
}

em, i 
{
  font-style: italic;
  font-weight: inherit;
}

Unfortunately, Internet Explorer doesn't support "inherit." :-(

Upvotes: 0

Kevin
Kevin

Reputation: 13097

As Chris said, you don't have to use the exact CSS they provide religiously. I would just save a copy to your server, and edit to your needs.

Upvotes: 2

Ricky
Ricky

Reputation: 5377

I see what you are saying. I guess you can add a CSS rule like this:

strong em { font-weight: bold; }

or:

strong * { font-weight: bold; }

Upvotes: 0

Polsonby
Polsonby

Reputation: 22875

I would suggest avoiding anything which involves hacking the YUI files. You need to be able to update external libraries in the future and if your site relies on edited versions there is a good chance it will get cocked up. I think this is general good practice for any 3rd party library you use.

So I thought this answer was amongst the better ones

If in addition to using YUI reset.css, you also use YUI base.css, then you will be all set with a standard set of cross browser base styles.

Upvotes: 1

Chris Marasti-Georg
Chris Marasti-Georg

Reputation: 34650

Reset stylesheets are best used as a base. If you don't want to reset em or strong, remove them from the stylesheet.

Upvotes: 2

Ricky
Ricky

Reputation: 5377

If in addition to using YUI reset.css, you also use YUI base.css, then you will be all set with a standard set of cross browser base styles.

LINK: http://developer.yahoo.com/yui/base/

Upvotes: 6

sparkes
sparkes

Reputation: 19503

As long as your styles are loaded after the reset ones they should work. What browser is this? because I work in a similar way myself and I've not hit this problem I wonder if it's something in my testing at fault.

Upvotes: 2

Related Questions