继承css属性 [英] Inherit css properties

查看:33
本文介绍了继承css属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对css只有基本的了解,有没有可能从一种样式继承属性到另一种样式.例如,我可以将默认段落标记设置中指定的字体大小继承到超链接标记中.

I have only a basic knowledge of css, is it possible to inherit a property from one style into another style. So for instance I could inherit the font size specified in my default paragrah tag settings into my hyperlink tags.

我想这样做的原因是为了更容易维护多种样式.

The reason I want to do this is to make it easier to maintain multiple styles.

推荐答案

您可以像这样同时为两个元素定义通用样式:

You can define common styles for two elements at once like so:

p, a {
    font-size: 1em;
}

然后根据需要扩展每个属性:

And then extend each one with their individual properties as you want:

p {
   color: red;
}

a {
   font-weight: bold;
}

请记住:在样式表中稍后定义的样式通常会覆盖之前定义的属性.

Keep in mind: Styles defined later in a style sheet generally override properties defined earlier.

额外:如果您还没有,我建议您获取 FirebugFirefox 扩展,以便您可以查看页面上的元素接收的样式以及它们从何处继承.

Extra: If you haven't already, I recommend getting the Firebug Firefox extension so you can see what styles the elements on your page are receiving and where they are inherited from.

这篇关于继承css属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆