Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS reset that sets everything to default values

Tags:

css

I'm working on a browser extension that adds it's UI to the pages DOM. On some pages I have the problem certain styles affect my UI. To counter this I keep my UI underneath a common root which resets most of the styles to the default value.

Sometimes I missed things which causes visual glitches in my UI. (i.e. the pages CSS file sets form { width: 80%; } so I need to add form { width: auto; } to my reset styles.

Is there a collection of styles that reset every CSS attribute to the value that is declared as default by the standard for every element?

like image 835
Martin Thurau Avatar asked Oct 23 '13 13:10

Martin Thurau


People also ask

How do I Reset CSS to default?

Use the initial keyword to set a property to its initial value. Use the inherit keyword to make an element's property the same as its parent. Use the revert keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist).

What is base reset in CSS?

Resetting your styles, commonly referred to as CSS Reset or Reset CSS is the process of resetting (or more accurately – setting) the styles of all elements to a baseline value so that you avoid cross-browser differences due to their built-in default style settings.

What is normalize CSS?

"Normalize. css is a small CSS file that provides better cross-browser consistency in the default styling of HTML elements. It's a modern, HTML5-ready, alternative to the traditional CSS reset." This component is a direct port of Normalize v1. 1.0 from the Normalize.

What is the difference between Reset CSS and normalize CSS?

Normalizing maintains useful defaults over non-stylizing everything and it won't clutter your dev tools window. Moreover, Resetting is meant to strip all default browser styling on elements. For e.g. margins, paddings, font sizes of all elements are reset to be the same.


2 Answers

I have come across the same problem. The usual CSS normalizers listed by the other answers does not answer the question because it is made to cancel the differences across the browser's default styles.

In the context of an extension, I needed to cancel every specific style that may exist on a random website.

I have come across this solution (I am not sure if it was possible at the time of the question, 7 years ago).

.your-container-class,
.your-container-class *,
.your-container-class *::before,
.your-container-class *::after {
    all: initial;
}

So far it seems to achieve the goal by removing the differences across websites. The downside is that it resets even some default styles (ol, ul, li not behaving like lists for example).

like image 131
Sebastien C. Avatar answered Sep 19 '22 16:09

Sebastien C.


  1. Eric Meyer’s “Reset CSS” 2.0
    (the original one)

  2. HTML5 Doctor CSS Reset
    (extends the Eric Meyer's one to improve HTML5 tags reset)

  3. Yahoo! (YUI 3) Reset CSS
    (based on Normalize.css)

  4. Universal Selector ‘*’ Reset

  5. Normalize.css 1.0 2.1.3
    ("…as used by Twitter Bootstrap, HTML5 Boilerplate, YUI 3, Pure, TweetDeck, Soundcloud, Medium, NASA, GOV.UK, Guardian, Rdio, Favstar, iA, and many others.")

There are others, but this were (and still are) the 2012’s most popular CSS Reset scripts.

like image 26
Andrea Ligios Avatar answered Sep 18 '22 16:09

Andrea Ligios