Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. In April, nonresidential building starts fell 37% from March, while residential dropped 25%. The decline in nonbuilding construction starts was more tepid, falling just 5% due to strong activity in streets and bridges.' Read more Commercial Real Estate’s Survival Plan Looks a Lot Like WeWork (Bloomberg) - May 14.
In CSS, we often declare more than what we required, overwriting other styles definition. However, in CSS there are certain rules that we must obey for us to properly overwrite the rule that we want as well. In this article, you will find all the CSS order priority tips that can benefit you in writing effective and efficient CSS definition.
The correct way of declaring a sequence anchor pseudo-classes is shown below,
If you tried to mess the sequence up, you will find that the above 'action' will be overlapped. Here are some important things to take note of when using anchor pseudo-classes.
anchor pseudo-classes will be easily achieved with the above rule in mind.
Ever wonder what will happen if you have two rule that contains the same weight? Something like the one shown below?
Just remember this, when two rules have the same weight, the last rule specified wins! Black color will display in this case.
!important is a powerful tool to specific a CSS definition as important. Hence, if the previous example were being declared and one of it is being set to !important, the one with the !important will have the highest priority!
In this case, the first one will display instead. Here are some points you should take note of when using !important.
It is as important as !important that you take note of the above point! This means that if you as an author declare !important over a style that contains color or font size such as the one above, whenever user tried to overwrite your colors or font size will deem invalid. Especially for older users who will really need such capability to overwrite your default font-size and colors! This might result in poor usability due !important.
Another interesting thing you might want to know. If you have 4 specification on a single element such as the one below,
Assuming the HTML element is
which color will appeared? The answer is black! How do i know? Because i tested it! Just Kidding. The answer is pretty simple. In CSS, the more specific the style is define, the more likely it will be used over the less specific ones. So how do we know how specific it is being define? Lucky, there is a way to calculate such specificity in CSS and here's how:
Once you done that you will have 3 digit. Each digit is meant for each description above. Next, arrange them from left to right starting from the first description to the third one. And you will have something like this.
Where a, b and c is equivalence to 1., 2. and 3. on the description. Hence we get our specificity as follows
In numeric number, 100 is bigger than 14, 11 and 1. Therefore, black will appeared instead of the others. I think the explanation is pretty clear now. But how do we calculate this when there is a specificity of a id/class/html that have more than a digit? In this case, you may need to convert the numbers to a larger base to end up with three digits.
The above mention CSS order priority tips and tricks will be pretty useful for people who are not aware of such things in CSS. Furthermore, this can greatly help out people to avoid using too much !important and reduce the overall design usability. Nonetheless, if you guys have any other CSS order priority tips and tricks to share. feel free to spam the comments below!
No related posts.