Learn More About CSS Specificity

Learn More About CSS Specificity

CSS specificity is an interesting topic. As the project gets bigger, the number of CSS rules in our CSS files get larger — and things start behaving in an undesired manner.

CSS specificity is an interesting topic. As the project gets bigger, the number of CSS rules in our CSS files get larger — and things start behaving in an undesired manner. This leads to many of us using the !important condition with different elements.

To understand specificity, let’s revise some basics, and I’ll add some of my own nomenclature to it.

Different Selectors

There are three different group of selectors.

  1. The #id selector
  2. The .class selector, the attribute selector (a[target=”_blank”] ), and the pseudo-class selector (button:hover).
  3. Elements (nav) and pseudo elements (p::first-line).

To make things simpler and easier to understand, I’ll call the first group the gold group, the second group the silver group, and the third group the bronze group.

Understanding specificity

This will be a hands-on tutorial, and we’ll start with the following basic HTML file.

sepecificity-1.html

<html>

<head>
  <title>CSS Specificity</title>
</head>

<body>
  <div class="main">
    <p id="para">This is my first para</p>
  </div>
  <style>
    * {
      padding: 0px;
      margin: 0px;
    }
  </style>
</body>

</html>

We’ve added a universal rule using the * selector to remove any browser-specific default padding or margins. The * selector overrides any browser defaults.

Lets’ begin.

What would the following CSS do?

specificity-1.css

p {
      color: red
    }

    p {
      color: blue;
    }

It would make the p tag’s font color appear blue — since in CSS, the rule that lies below in a CSS file takes precedence over what lies above it.

Now what would the following CSS do ?

specificity-2.css

div p {
      color: red
    }

    p {
      color: blue;
    }

We have two rules.

  1. The div p rule contains two tags. Since tags belong to the bronze group, we can say this rule has two bronze selectors (selectors analogous to the Olympics medals).
  2. The prule contains only one tag — one bronze selector.

The rule with the highest tally of selectors (gold, silver, bronze) in that specific order takes precedence — just like the leader board of countries in the Olympics. This is CSS specificity in a nutshell.

More examples

What would the following CSS do?

specificity-3.css

.main p {
      color: green;
    }

    div p {
      color: blue;
    }

Let’s count the selectors for the rules.

  1. .main p is a class selector that belongs to the silver group and a tag selector that belongs to bronze group. Hence, we have one silver and one bronze.
  2. div p is two Bronze selectors.

The color would be green.

One silver and one bronze is more important than zero gold, zero silver, and n bronze selectors. It doesn’t matter how large the number of n is.

Lets’ see one more example.

specificity-4.css

#para {
      color: black
    }

    .main p {
      color: green;
    }

    div p {
      color: blue;
    }

We have three rules.

  1. One gold selector
  2. One silver and one bronze selector
  3. Two bronze selectors

And the answer is simple: The color would be black.

It works exactly like the leader board containing different countries at the Olympics. Once you know the individual medal tally, you can figure it out.

Conclusion

Just count the number of selectors in a category, and you’ll know which rule would take precedence over which rule. If the tally is the same, the rule that lies below in the CSS file would take preference.

7 Best Vue CSS Component for Your App

7 Best Vue CSS Component for Your App

Vue CSS frameworks are great for many reasons; code is more universally understood, web applications are easier to maintain, and prototyping becomes less of an extra step.

Vue CSS frameworks are great for many reasons; code is more universally understood, web applications are easier to maintain, and prototyping becomes less of an extra step and more part of the development process.

1. Tailwindcss-Vue

Tailwindcss-Vue is a library of UI components for Vue.js built using the Tailwind CSS utility-first CSS framework.

Download: https://github.com/advanced-data-machines/tailwindcss-vue/archive/master.zip

2. @zeit-ui/vue

Vue implementation for Zeit Style, originating from Zeit Design.

@zeit-ui/vue is a Vue implementation for zeit style, originating from Zeit Design. Lean more at GITHUB.

The design of the Zeit is concise and aesthetic feeling, this is an important reason for popular of Zeit. Now you can use them through the @zeit-ui/vue.

Download: https://github.com/zeit-ui/vue/archive/master.zip

3. CSSeffectsSnippets

Click on the animation to copy it to your clipboard

Demo: https://emilkowalski.github.io/css-effects-snippets/

Download: https://github.com/emilkowalski/css-effects-snippets/archive/master.zip

4. Vue Cirrus

A fully responsive and comprehensive CSS framework with beautiful controls and simplistic structure. Cirrus is designed to be adaptable to existing themes or when starting fresh. These are the Vue Components for this CSS framework.

Demo: https://florianwoelki.github.io/vue-cirrus/#/

Download: https://github.com/FlorianWoelki/vue-cirrus/archive/master.zip

5. Vue CSS Modules

Seamless mapping of class names to CSS modules inside of Vue components.

Download: https://github.com/fjc0k/vue-css-modules/archive/master.zip

6. BG MixMaster 90 — CSS Background Grid /Pattern Generator

make a background grid (like graph paper) using only one background gradient property and ended up with this killer mix tape for making all kinds of background grids and patterns.

Download: https://codepen.io/jasesmith/pen/YZEYRL

7. CSSOBJ

CSS Rules from JS, change rules dynamically, CSSOM, css modules, auto vendor prefixer, media query for old browsers.

CSS in JS solution, create CSSOM and CSS rules from js, features:

  • CSS Rules create and diff
  • CSS modules with local class
  • Auto vendor prefixer
  • Media query for old browsers
  • Dynamically change CSS

Demo: https://cssobj.github.io/cssobj-demo/

Download: https://github.com/cssobj/cssobj/archive/master.zip

Guide to Python Programming Language

Guide to Python Programming Language

Guide to Python Programming Language

Description
The course will lead you from beginning level to advance in Python Programming Language. You do not need any prior knowledge on Python or any programming language or even programming to join the course and become an expert on the topic.

The course is begin continuously developing by adding lectures regularly.

Please see the Promo and free sample video to get to know more.

Hope you will enjoy it.

Basic knowledge
An Enthusiast Mind
A Computer
Basic Knowledge To Use Computer
Internet Connection
What will you learn
Will Be Expert On Python Programming Language
Build Application On Python Programming Language

Learn Python Programming

Learn Python Programming

Learn Python Programming

Description
Learn Python Programming

Learn Python Programming and increase your python programming skills with Coder Kovid.

Python is the highest growing programming language in this era. You can use Python to do everything like, web development, software development, cognitive development, machine learning, artificial intelligence, etc. You should learn python programming and increase your skills of programming.

In this course of learn python programming you don't need any prior programming knowledge. Every beginner can start with.

Basic knowledge
No prior knowledge needed to learn this course
What will you learn
Write Basic Syntax of Python Programming
Create Basic Real World Application
Program in a fluent manner
Get Familiar in Programming Environment