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

一笑奈何 提交于 2019-11-27 22:16:00

问题


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?


回答1:


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:


I would use this rule to override the YUI reset:

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

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



回答3:


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/




回答4:


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.




回答5:


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.




回答6:


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




回答7:


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.




回答8:


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.




回答9:


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



回答10:


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



来源:https://stackoverflow.com/questions/20107/yui-reset-css-makes-strongemthis-not-work-em-strong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!