Martin Thurau
Martin Thurau

Reputation: 7644

CSS reset that sets everything to default values

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?

Upvotes: 7

Views: 16710

Answers (6)

Sebastien C.
Sebastien C.

Reputation: 4833

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).

Upvotes: 5

Andrea Ligios
Andrea Ligios

Reputation: 50193

  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.

Upvotes: 4

Owen C. Jones
Owen C. Jones

Reputation: 1495

Yes, absolutely.

There are two schools of thought to this. One is the zeroing style reset sheets, which basically remove all margin, padding and other such settings from the css. A good example of this is Eric Meyer's Reset CSS

The other approach is to set everything to roughly what you'd sensibly expect it to be, setting a reasonably looking margin to paragraphs and headings, indenting lists etc. A good example of this is Normalize.css

Some browsers also support the initial value, which sets the value of a property back to what it intially was. It's not widely supported enough to use in production, IMO.

Upvotes: -1

Joel Worsham
Joel Worsham

Reputation: 1150

I recommend using a quick Google search to find something like so: http://meyerweb.com/eric/tools/css/reset/

You can implement the reset in as-is and then if any problems arise down the road, simply add to it as needed.

Be aware that some pre-made CSS resets require a shout-out to using them.

Upvotes: -1

Claudio Holanda
Claudio Holanda

Reputation: 2566

As you are applying your styles to different pages with different unique styles, its hard to say if you will get success on removing all styles from all pages with some CSS reset.

But maybe these can help:

Normalize.css (used by many CSS frameworks)

CSS Reset by Meyer

Upvotes: -2

veelen
veelen

Reputation: 1914

Html5 boilerplate has an normalize.css which sets al lot of css styles to a default. http://html5boilerplate.com/

Upvotes: -2

Related Questions