Mcloving
Mcloving

Reputation: 1410

Stop inheriting from user agent

I am trying to create a styled h4.

But my h4 keeps inheriting from some user agent?

What is this user agent.

How can I stop it from doing so. Its adding effects that I dont want.

enter image description here

Upvotes: 3

Views: 1423

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201588

No, the h4 element (or the h2 element, as in your screen shot) does not inherit from some user agent. Instead, it gets property values directly from a user agent stylesheet. “User agent” means a browser in practice (in principle, it could be an indexing robot, too, for example).

You can stop that simply by assigning properties in your style sheet. In fact, you have done that in your example: font-size and font-weight have been overridden. The setting display: block could be overridden e.g. by adding display: inline into your style sheet.

The margin issue is trickier, as WebKit browsers have their oddities there, and the -webkit-margin properties are shown as if they had not been overridden. But in fact they are ignored when the standard margin properties are set, as they are in your case; check out the “Metrics” pane to see this.

So you are already overriding the user agent style sheet settings. In general, a user agent style sheet could contain anything, but using a reset.css style sheet is still a wrong approach mostly. The default style sheet for HTML 4 in the CSS 2.1 spec is fairly realistic and tells you what to prepare for, e.g. display, margin, font-weight, and font-size for headings.

Upvotes: 1

Strelok
Strelok

Reputation: 51451

To stop the inheriting from the user agent (styles your web browser chooses by default for various HTML elements) madness you need to use a good CSS "reset".

Read http://meyerweb.com/eric/tools/css/reset/ for an intro into a "reset".

A list of different "resets" http://www.cssreset.com/

Also if you are using some framework like Twitter Bootstrap for example it will already have a reasonable reset included.

Upvotes: 1

Related Questions