Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting font-size for all text except <h1> <h2> etc

Tags:

html

css

I'm applying CSS to a box of my page which may contain <div> <table> <p> and other elements, and just plain text.

I want all the text to be the same font size, with exception for text within tags such as <h1> <h2> <h3>

With objectid "mybox" my simple CSS font modifier was

.mybox * {
font-size: 13px;
}

The problem is that this also sets the font for any <h2> elements and so on. I could add a class to my <h2> elements and another selector to override the font size again, but that feels very backwards.

What is a good way to take care of this?

I found the not() selector which works for classes, but I couldn't find one for html elements like <h2> to exclude them from my "global" font modifier.

like image 201
user985366 Avatar asked Oct 29 '25 01:10

user985366


2 Answers

Use the :not selector with those "unwanted" elements:

.mybox *:not(h1):not(h2):not(h3) {
  font-size: 13px;
}
<div class="mybox">
  <h1>foo</h1>
  <h2>bar</h2>
  <h3>Hans</h3>
  <label>Gruber</label>
  <p>Goku</p>
  <div>Yoda</div>
</div>

JSFiddle

like image 61
Peter Wilson Avatar answered Oct 30 '25 18:10

Peter Wilson


you can set your font style on the body and add :not(h1):not(h2) for not include style on them.

like image 34
Sirlero Avatar answered Oct 30 '25 18:10

Sirlero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!