css样式表定义的顺序很重要吗? [英] Does the order of css stylesheet definitions matter?

查看:108
本文介绍了css样式表定义的顺序很重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个样式表。第一个是一个样式表,有一些样式,我想用作默认值。根据几个因素,用于生成页面的代码可能包含一些样式表,其值应该覆盖默认值。

I have several stylesheets. The first one is a stylesheet with some styles that I would like to use as defaults. Depending on several factors, the code being used to generate the page may include some stylesheets with values that should override the defaults.

如果我使用这个,我可以相信默认样式表中的值将被其他样式表的值覆盖?我使用类选择器,当名称匹配时将覆盖值。

If I use this, can I trust that the values in the default stylesheet will be overridden by the values from the other stylesheet? I am using class selectors and will override values when the names match.

<link href="defaults.css" rel="stylesheet" type="text/css"/> 
<link href="valuestooverridedefaults.css" rel="stylesheet" type="text/css"/> 

这需要在所有浏览器(包括手机)上运行。如果可能,我想避免使用!important。

This needs to work on all browsers, including mobile. I'd like to avoid having to use "!important", if possible.

谢谢!

推荐答案

有一个定义的级联,其中样式排序并应用。
当声明具有相同的重要性(权重), origin specifity 时,则后面的声明获胜。大多数回答都包含重要性 特性,但不包含起源

There is a defined cascade in which the styles are sorted and applied. When declarations have the same importance (weight), origin and specifity then the latter declaration wins. Most answers cover importance and specifity here but not origin.

关于 CSS级联的非常好的幻灯片。

Here are some very good slides about CSS Cascades.

这篇关于css样式表定义的顺序很重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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