Change font size in div using CSS

In the DIV, I put some text / html code that is loaded from the database. This text sometimes contains font size definitions (for example: font size = "3"). There is a way to override this font size in this particular DIV using CSS.

I am grateful for any help.

+7
source share
4 answers

Assuming markup similar to the following:

<div> <font size="1">Some text at 'size="1"'</font> and natively-sized text, with more at <font size="26">'size="26".'</font> </div>โ€‹ 

Then you can explicitly specify CSS for inherit font-size from the parent element:

 div { font-size: 1.5em; } div font { font-size: inherit; } 

JS Fiddle demo .

Please note, of course, that font deprecated and therefore should not be used (since support for the item may cease without notice and / or changes without warning).

By the way, while !important will cause the ad to override the usual cascade of styles, it will take a sledgehammer to crack a nut; and, if it can be avoided (and in this case, it seems, it can be avoided), it should be, as this complicates the subsequent debugging of styles and the related inheritance problems.

In addition, this refers to the symptom of your problem; the problem you are really facing is the presence of font tags in your content / database. This needs to be fixed by deleting the elements and replacing them with the corresponding elements, such as em , span , etc ...

Literature:

+9
source

Using CSS! important , you tell the browser to overwrite any font size defined inside your div :

From the above link, he reads:

However, for balance, the expression โ€œ! Importantโ€ (the delimiter token โ€œ!โ€ And the keyword โ€œimportantโ€ follows the declaration) takes precedence over the normal declaration.

Example

See a working script. Example!

 .htmlContents * {font-size:10px!important;} <div class="htmlContents">my database html content</div> 
+3
source

One idea: give these text tags an identifier or class, and then use JavaScript to search for these elements and change the style on them.

0
source

How to remove font descriptors from text before pasting into a div? Then just create a div with the font size.

0
source

All Articles