Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite font: in CSS

Tags:

html

css

fonts

I have an existing web page on which there is a CSS file that I am unable to change which has the following CSS in it:

body {
    background: none repeat scroll 0 0 #FFFFFF;
    color: #000000;
    font: 0.8em Verdana,Arial,sans-serif;
}

I am adding in an additional CSS file, and for the part of the page that its controlling I need to be able to overwrite the font size that is above, and set the size to the auto size as supplied by the browser and a different font family.

I know about putting the !important tag on there so changing the font family hasn't been a problem, but if I don't put a size in there it strips it out when the page compiles.

I thought I could use font-size: to override it, but I'm unclear as to how to set that to be whatever the browser has automatically.

All help would be much appreciated! I'm a bit of a CSS novice!

like image 363
hlh3406 Avatar asked Jul 29 '15 10:07

hlh3406


People also ask

Can you change font with CSS?

To change font type purely with HTML, use the CSS font-family property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.

Can HTML style be overwritten by CSS?

You can add your styles in the required page after the external style sheet so they'll cascade and overwrite the first set of rules.

How do you change text in CSS?

The text “Old Text” needs to be hidden first and a new text has to be positioned exactly where the old text was. To do so, we change the visibility of this text using CSS to hidden first. Then we add a new text at the exact same position, using the pseudo elements and corresponding explicit positioning.

How do you change the font style?

Open Settings. Tap Display. Tap Font and screen zoom. Select your choice of Font Style and you're done.


2 Answers

try

html body {
    /* your stuff here */
}

By using the html element, it makes the selector more specific and applies the overwrite.

Example:

body {
    font-family: sans-serif;
    font-size: 30px;
}

html body {
    font-family: serif;
    font-size: 1em;
}
Hello world.<br>
This is the 'normal' size because of the html element selector allowing an override.

Edit: The answer has been accepted but I changed the font-size to 1em. As this is the initial body tag it should reset the the browser default size. This was asked in the question and I didn't cover this.

like image 151
John Reid Avatar answered Sep 17 '22 18:09

John Reid


Well the default font-size is medium.

.wherever{
    font-size: medium;
}

That will overwrite the body font size that is added.

like image 38
ZeroBased_IX Avatar answered Sep 19 '22 18:09

ZeroBased_IX