YUI重置CSS使<strong> <em>无法正常工作</em> </strong>

时间:2008-08-21 14:36:41

标签: css yui

YUI Reset CSS中的这一行给我带来了麻烦:

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

这使我的em不是斜体而我的strong不是粗体。哪个没关系。我知道如何在我自己的样式表中覆盖它。

strong, b 
{
  font-weight: bold;
}

em, i 
{
  font-style: italic;
}

当我的文字同时为emstrong时,就会出现问题。

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

我对strong的规则使其变为粗体,但YUI对em的规则使其再次正常。我该如何解决这个问题?

10 个答案:

答案 0 :(得分:17)

如果您的强烈声明是在YUI之后发出的,那么你的声明应该覆盖它。你可以这样强迫它:

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

如果您仍然支持IE7,则需要添加!important

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

这有效 - 请亲自看看:

/*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>

答案 1 :(得分:7)

我会使用此规则来覆盖YUI重置:

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

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

答案 2 :(得分:6)

如果除了使用YUI reset.css之外,还使用了YUI base.css,那么您将使用一组标准的跨浏览器基本样式进行设置。

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

答案 3 :(得分:3)

当我将YUI重置添加到我的库存CSS文件的顶部时,我遇到了类似的问题。我发现对我来说最好的事情就是简单地删除所有

font-weight: normal;
来自YUI重置的

声明。我没有注意到这会影响“跨浏览器”。

我的所有声明都是在YUI重置之后,所以我不确定他们为什么没有生效。

答案 4 :(得分:2)

只要您的样式在重置后加载,它们就可以正常工作。这是什么浏览器?因为我自己也以类似的方式工作,而且我没有遇到这个问题,我想知道这是否是我测试中的错误。

答案 5 :(得分:2)

重置样式表最好用作基础。如果您不想重置em或strong,请从样式表中删除它们。

答案 6 :(得分:2)

正如克里斯所说,你不必使用他们提供的确切的CSS。我只需将副本保存到您的服务器,然后根据您的需要进行编辑。

答案 7 :(得分:1)

我建议避免任何涉及黑客攻击YUI文件的内容。您需要能够在将来更新外部库,如果您的站点依赖于已编辑的版本,则很可能会出现这种情况。我认为这是您使用的任何第三方库的一般良好做法。

所以我认为this回答是更好的回答

  
    

如果除了使用YUI reset.css之外,还使用了YUI base.css,那么您将使用一组标准的跨浏览器基本样式进行设置。

  

答案 8 :(得分:0)

我以为我有一个理想的解决方案:

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

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

不幸的是,Internet Explorer不支持“继承”。 : - (

答案 9 :(得分:0)

我明白你在说什么。我想你可以添加这样的CSS规则:

strong em { font-weight: bold; }

或:

strong * { font-weight: bold; }
相关问题