开发者

Does the CSS cascade apply significance based on the order in which you add classes to HTML elements?

开发者 https://www.devze.com 2023-02-12 23:26 出处:网络
Quite confused here. <html> <head> <style> .one { 开发者_开发问答font-weight: normal;

Quite confused here.

<html>
<head>
<style>
.one
{
开发者_开发问答    font-weight: normal;
}

.two
{
    font-weight: bold;
}
</style>

<body>
<p class="two one"> Test!!!!!</p>
</body>

</html>

Why is Test bold? I'm clearly defining "normal" for the font weight "after" the bolded one?

I thought CSS did the cascading based on what order the classes were added right? Not the location in the file?


CSS doesn't care what order you specify the classes inside your class attribute.

Here, both classes have equal specificity, so the class lower down in your CSS "wins".

Specifics on CSS Specificity - a well written article explaining specificity.

Pointless demo of your code: http://jsfiddle.net/JwhmE/


It doesn't go off the order of the classes on the div but the order they are defined in the style rule.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号