Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select * but exclude <body>? Or set <body> to default style?

Browsers usually set different default styles for elements. Users can also override the defaults using custom stylesheets.

I often override these default styles using my own styles, e.g.:

* {padding:0; margin:0; }

However, I wish to respect the default stylesheet for certain element attributes, e.g. the <body>'s default padding and margin. I tried:

*    { padding:0;       margin:0;       }
body { padding:default; margin:default; }

But it doesn't work. Neither does initial.

Is there a way to solve this problem by selecting all elements but excluding <body>?

like image 460
Pacerier Avatar asked Jun 13 '11 09:06

Pacerier


2 Answers

Is there a way to solve this problem by selecting all elements but excluding <body>?

Since everything that is displayed in the viewport consists of <html>, <body> and <body>'s contents by default, you can just select html, and all of body's descendants:

html, body * { margin: 0; padding: 0; }

default doesn't work because there is no such keyword. initial doesn't work because the initial margins are 0. It is not possible to reset a property to its browser-given default value after you have changed it using CSS.

like image 177
BoltClock Avatar answered Sep 22 '22 15:09

BoltClock


html, head, head *, body * { }
like image 23
Quentin Avatar answered Sep 23 '22 15:09

Quentin