What’s the difference between html[lang=”en”] and html:lang(en) in CSS?

In HTML, both the :lang() pseudo-class and the attribute selector will match an element with the corresponding lang attribute. The difference is that a browser may have other ways of determining the language of a given element when testing against the :lang() pseudo-class which may be defined by the document language and/or the implementation, whereas … Read more

Is there any pros and cons if i use always CSS Class instead CSS ID for everything?

One big difference: in CSS, a class has a lower importance level than an ID. Imagine that each specification in a CSS declaration added a certain number of points to that declaration’s value. Let’s say the points go something like this (totally made up, but whatever): Tag name (‘a’, ‘div’, ‘span’): 1 point Class name … Read more

Selecting an element that doesn’t have a child with a certain class

:not(:has()) Note: Limited support for old browsers. The example below demonstrates the combination of the :not() and :has() pseudo-classes to select elements that do not have a specified child. div:not(:has(p)) { background: powderblue; } div:not(:has(p)):hover { color: blue; background: azure; } <div> <h1>Does Not Have a Paragraph</h1> </div> <div> <h1>Has a Paragraph</h1> <p>Paragraph</p> </div> As … Read more

How can I use a not:first-child selector?

One of the versions you posted actually works for all modern browsers (where CSS selectors level 3 are supported): div ul:not(:first-child) { background-color: #900; } If you need to support legacy browsers, or if you are hindered by the :not selector’s limitation (it only accepts a simple selector as an argument) then you can use … Read more

How to get nth-child selector to skip hidden divs [duplicate]

When the user clicks on a button, I hide few blocks by display:none, and the problem occurs. The nth-child selector also counts hidden elements. Is there way to ignore those specific blocks, so that again every row has different style? The problem is that the nth-child() selector looks at all siblings under the same parent … Read more

Is anyone actually using css namespaces?

They cover completely different use cases. CSS namespaces are for applying CSS to XML documents that mix elements from different XML namespaces. e.g. so you can target <foo:p> and <bar:p> without confusion. SMACSS covers techniques for writing robust CSS that doesn’t interfere with other parts of the page. e.g. so that .title in your address … Read more

CSS2 Attribute Selectors with Regex

As for CSS 2.1, see http://www.w3.org/TR/CSS21/selector.html#attribute-selectors Executive summary: Attribute selectors may match in four ways: [att] Match when the element sets the “att” attribute, whatever the value of the attribute. [att=val] Match when the element’s “att” attribute value is exactly “val”. [att~=val] Match when the element’s “att” attribute value is a space-separated list of “words”, … Read more