Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CSS Specificity

Posted on Aug 18 In CSS, the level of importance of styles applied to an element is governed by Specificity. it determines which CSS rule set takes precedence when multiple rules are applied to the same element.Here are some examples where it applies:Inline Styles: These have the highest specificity and therefore have the highest priority. They are applied directly to an element within its Style attribute.ID Selectors: These have a higher specificity than class and element selectors. But if using an ID to style multiple elements, it's important to remember that it's good practice to keep unique IDs throughout the page.Selectors class: They are less specific than IDs but more specific than element selectors. You can apply the same class to multiple elements and apply similar styles to all of them.Element Selectors: They are the least specific. These affect all elements of the same type (eg all paragraphs, all headings (p, h1), etc.) and can easily be affected by more specific rules.When multiple styles are applied to the same element and there are conflicts, the rule with the highest specificity will prevail. If two or more rules have the same specificity, the last rule found in the code will be applied.It is important to understand these hierarchies of specificity so that you can control and predict how styles will be applied on your web page.Veamos codigoWhat color do you think is painted in the div? Well, blue since the id-selector has greater specificity.If an inline style was put in the code, it would take that value that we put in it and ignore the others.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Sriparno Roy - Aug 9 Nevo David - Jul 24 Conner Ow - Aug 6 Matija Sosic - Jul 25 Once suspended, monkdev will not be able to comment or publish posts until their suspension is removed. Once unsuspended, monkdev will be able to comment and publish posts again. Once unpublished, all posts by monkdev will become hidden and only accessible to themselves. If monkdev is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Jhosep. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag monkdev: monkdev consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging monkdev will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

CSS Specificity

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×