css-specificity

Specificity rules for comma delineated lists

百般思念 提交于 2019-12-04 14:33:38
When using Cascading Style Sheets I have observed the order of specificity as follows: 1st Laws : In-line Styles 2nd Laws : Number of ID Selectors 3rd Laws : Number of Class Selectors 4th Laws : Number of Element Selectors So, items with in-line styles came first, followed by declarations with one or more ID selectors, followed by declarations with one or more class selectors, followed by declarations with one or more element selectors. With more IDs, classes and elements meaning more precedence, respectively. From this viewpoint I was unable to comprehend where comma delineated lists of IDs,

Why doesn't background color on body work?

独自空忆成欢 提交于 2019-12-04 13:57:05
When viewing the code below in my browser the background is white. The universal selector * has the lowest specificity , and the body selector comes after the universal selector. Shouldn't it be grey? * { background-color: white; } body { background-color: grey; } Let's break down the code in the question: * { background-color: white; } body { background-color: grey; } This is saying: Select every element and make its background color white. Select the body element and make its background color grey. Well, if the universal selector says select all elements , this would include the root element

Same specificity, after taking placement into consideration, :first-letter always wins?

梦想与她 提交于 2019-12-04 02:21:19
Take a look at this jsfiddle: http://jsfiddle.net/ZNddz/ .intro:first-letter { font-size: 130px; } span.letter { background-color: red; font-size: 30px; } p { font-size: 80px; } The first rule consist of one class selector and one pseudo-element selector = 11 The second rule consist of one class selector .letter and one tag selector span = 11 Both rules have same specificity so it is reasonably to believe that the winner should be the last style. Obviously it is not the case. So I decided to add a background-color property to the second rule and as you can see it has a height of 30px. I deduce

Efficient Algorithm To Compare Specificity Of CSS Rules

落爺英雄遲暮 提交于 2019-12-04 01:13:40
问题 I was wondering what an efficient algorithm would be in the following scenario: Given a parsed set of css rules, eg. p.pStyle{margin-bottom:20px;font-family:Arial;} p{font-family:Verdana;} p.anotherPStyle{margin-bottom:10px;} from a css stylesheet, it is possible that several rule sets apply to a given element (say a <p class="pStyle anotherPStyle">hello</p> in my document). I need to determine what rules in the stylesheet apply to a given element firstly (so here that is p, pStyle and

Precedence of multiple classes defining color property being set by declaration order rather than specification order

[亡魂溺海] 提交于 2019-12-03 11:02:37
问题 Given two classes of equal specificity defining the color property I thought the last class listed in the element class attribute would take precedence. From http://htmlhelp.com/reference/css/structure.html: Order of Specification To make it easy, when two rules have the same weight, the last rule specified wins. In the following vacuum code example the order in which the class rule set is defined determines precedence. Here the last, or most recent, class rule set definition takes precedence

Using multiple classes in one element and specificity

旧时模样 提交于 2019-12-03 10:07:44
Just wondering when you use multiple classes on the one element such as class="foo bar" and those classes are setup as below: .foo { margin-right: 10px; } .bar { margin-right: 0px; } Which class will have specificity? Will the margin be 10px or 0px? Rion Williams It works based on precedence within the CSS. Therefore the item to occur most recently will override any previous styles. CASE 1 .foo { background : red; } .bar { background : blue; } class = 'foo bar' would be blue in this instance. CASE 2 .bar { background : blue; } .foo { background : red; } class = 'foo bar' would be red in this

Order by CSS Specificity

爷,独闯天下 提交于 2019-12-03 06:48:32
My main goal is to try to reorder a CSS style block based on specificity. I previously had helped from SO and I managed to produce this function. See gist . Here is an example: function specificity($selector){ // https://gist.github.com/2774085 } $compare = function($a, $b) use ($specificity) { return $specificity($a) - $specificity($b) }; $array = css_array(); uksort($array, $compare); The above has been working great until I came across this CSS: html, body, body div{ background: transparent; } body { background-color: #D96F02; } This gets reordered into this: body { // 1 point background

Precedence of multiple classes defining color property being set by declaration order rather than specification order

时间秒杀一切 提交于 2019-12-03 01:25:55
Given two classes of equal specificity defining the color property I thought the last class listed in the element class attribute would take precedence. From http://htmlhelp.com/reference/css/structure.html : Order of Specification To make it easy, when two rules have the same weight, the last rule specified wins. In the following vacuum code example the order in which the class rule set is defined determines precedence. Here the last, or most recent, class rule set definition takes precedence. <style> .makeBlue {color: blue;} .makeGreen {color:green;} </style> <div> <p class="makeGreen

CSS selector cascading/specificity not working as expected

六眼飞鱼酱① 提交于 2019-12-02 05:26:35
问题 Details I'm working in FirefoxDeveloperEdition and experiencing unexpected selector prioritization. I've read through the Smashing Magazine article "CSS Specificity: Things You Should Know" and, insofar as I can tell, have constructed the CSS selectors as they ought be in order to achieve the intended level of specificity for each. However, the wrong declaration is being cancelled out. What's the issue, here? Have I not quite wrapped by head around the workings of selector specificity? Is

How to style :root without !important using proper specificity

最后都变了- 提交于 2019-12-02 01:15:44
Inside a Custom Element because border-color is set on the parent page, I can not make border-color work without resorting to !important :host([player="O"]) { color: var(--color2); border-color: var(--color2) !important; } The selector works fine, the color is set, so it is a Specificity issue Question: Is it possible without !important ? Working snipppet: window.customElements.define('game-toes', class extends HTMLElement { constructor() { super(); let shadowRoot = this.attachShadow({ mode: 'open' }); shadowRoot.innerHTML = 'Toes'; shadowRoot.appendChild(document.querySelector('#Styles')