12

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?

10 Answers 10

19

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>

2
  • 1
    +1 because THIS is the correct answer. The one marked as correct doesn't work on IE7 Apr 19, 2009 at 20:19
  • Thanks, Scott. You're right. The !important is necessary in IE7. May 20, 2009 at 18:57
7

I would use this rule to override the YUI reset:

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

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

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/

1
  • YUI base doesn't solve the problem. It makes strong bold and em italic, but doesn't resolve the conflict when the same text is wrapped in both tags. Jan 14, 2009 at 15:40
3

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.

2

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.

2

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

2

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.

1

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.

0

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; }
0

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." :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.