Skip to main content

The Truth About CSS Specificity

www.bram.usbram.us2 weeks ago in#Web Design Love50
The Truth About CSS Specificity

Me, at CSS Day 2022, talking about Specificity (and the Cascade) Whenever a post about Specificity in CSS – and by extension the Cascade itself – gets published I get very excited as it’s a core concept of the language that everyone should know. The more articles on this, the better! However, I also sometimes raise one of my eyebrows as sometimes I, unfortunately, encounter something that’s just outright wrong. To remove some of the confusion, here’s a list of misconceptions about Specificity in CSS … ~ # Table of Contents Misconception 1: Specificity is a decimal score Misconception 2: Using the style attribute adds Specificity Misconception 3: Using !important adds Specificity Learn More ~ # Misconception 1: Specificity is a decimal score Some, typically older, articles out there express Specificity as a decimal score, or mention that a thing like a class selector “adds 10 points”. This is inaccurate as it would imply that 11 element selectors with their “1 point each” would beat 1 class selector that only has “10 points”. Instead, Specificity is a triple (or a triad) that has three components: A, B, and C. The values for A, B, and C depend on what type of selector you use. A = id-like specificity B = class-like specificity C = element-like specificity It is often represented using the (A,B,C) notation. For example: (1,0,2). The alternative A-B-C notation is also commonly used. Specificities are compared by comparing the three components in order: the specificity with a larger A value is more specific; if the two A values are tied, then the specificity with a larger B value is more specific; if the two B values are also tied, then the specificity with a larger C value is more specific; if all the values are tied, the two specificities are equal. In code, it looks like this: const compare = (s1, s2) ={ if (s1.a === s2.a) { if (s1.b === s2.b) { return s1.c – s2.c; } return s1.b – s2.b; } return s1.a – s2.a; }; For example, (1,0,0) is a higher specificity than (0,10,3) because the A value in (1,0,0) (which is 1) is greater than the A value from (0,10,3) (which is 0). Also see this excerpt from my CSS Day 2022 talk about the cascade: Excerpt from my CSS Day talk on the Cascade, covering how to write and compare Specificity 💡 While you could represent the triad as a decimal by adding enough leading zeroes, it comes with its own set of challenges: the number you end up with is hard to read/parse + you would need to add “enough” zeroes to get a correctly sortable result. My advice here remains this: don’t. Where the confusion comes from: Back in CSS Selectors 3, the spec mentioned that you could concatenate the numbers to get the specificity. Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity. While it is caveated with “in a number system with a large base” the clause got ignored, most likely because the spec showed examples in base 10 – e.g.  » Read More

Like to keep reading?

This article first appeared on bram.us. If you'd like to continue this story, follow the white rabbit.

View Full Article
source Unsplash.com

On compliance vs readability: Generating text colors with CSS

#Web Design

Let's talk about Web Design

The term "web design" describes the layout of websites that are seen online. Instead of software development, it typically refers to the user experience components of website development. The primary focus of web design used to be creating websites for desktop browsers, but from the middle of the 2010s, designing for mobile and tablet browsers has gained significance.

What is a webdesigner?

A web designer is responsible for a website's look, feel, and occasionally even content. For instance, appearance refers to the colors, text, and images utilized. Information's organization and categorization are referred to as its layout. An effective web design is user-friendly, aesthetically pleasing, and appropriate for the target audience and brand of the website. Many websites focus on keeping things simple so that viewers won't be distracted or confused by additional information and functionality. Removing as many potential sources of user annoyance as possible is a crucial factor to take into account because the foundation of a web designer's output is a site that gains and nurtures the trust of the target audience.

Responsive and adaptive design are two of the most popular techniques for creating websites that function well on both desktop and mobile devices. In adaptive design, the website content is fixed in layout sizes that correspond to typical screen sizes, while in responsive design, information moves dynamically based on screen size. A layout that is as consistent as possible across devices is essential to preserving user engagement and trust. Designers must be cautious when giving up control of how their work will appear because responsive design can be challenging in this area. While they might need to diversify their skill set if they are also in charge of the content, they will benefit from having complete control over the final output.

What does a web design worker do?

A web designer is a member of the IT industry who is in charge of planning a website's structure, aesthetic appeal, and usability.

A skilled site designer must possess both technical know-how and creative graphic design abilities. They must be able to envision how a website will seem (its graphical design) and how it will operate (conversion of a design into a working website).

The terms web developer and designer are frequently used interchangeably but erroneously. In order to construct more complex interactions on a website, such as the integration with a database system, a web developer is frequently more likely to be a software developer who works with programming languages.