preview

CSS Specificity Case Study

Decent Essays

How You Can Handle the Issues Associated With CSS Specificity Web developers have to do a lot of coding work while creating websites or its pages. It doesn't matter whether you are creating a small or large website, you can't neglect the huge importance of fair coding practice. Coding a website or its pages is a very difficult task. Even a single mistake can ruin the overall effectiveness, productivity, and performance of the end product. Apart from this, a number of coding issues flourish when working with CSS (Cascading Style Sheets). When you have lots of website design, development, customization, and maintenance projects, you want to complete the website building tasks easily without compromising the quality of the end product. For …show more content…

However, this is not a great tool for web developers who develop CMSs. So, you can use CSS Preprocessors (such as SASS) in place of BEM. Tips to deal with Issues Associated With CSS Specificity 1. Subjoin The Existing Selector When you encounter a CSS specialty problem and have no option, but to choose a selector compared to another, then you should adjoin the existing selector with a new class, id, type selectors, and so on. Based on your specific needs, you can conjoin the reference selector and use it in your CSS or make use of the CSS to complete it by using the below-mentioned code snippet: .yellow{ .btn & { color: yellow; } } It will give the following result: .btn .yellow { color: yellow; } There are many web developers who want to use an HTML or body tag to prepend the selector. You can use some specific things available on your pages for that work, such as #wrapper, .page, etc. Furthermore, make the selector ready for any change you would like to make in the future. For that, you should use Sass which assists a lot in prepending selector in variable forms as detailed below: $PrependVar1: "header &"; $PrependVar2: "footer &"; .block { #{$PrependVar1} { width: 55%; } #{$PrependVar1} { width: 37%; } } This code will bring about the following results: header .block { width: 55%; } footer .block { width: 37%; } 2. Make Use Of A Self-Chained Selector Prepending a selector is an easy way to deal with the issues

Get Access