Is there a way to say use the current font weight without making it lighter/bolder?
font-weight
doesn't have a special keyword value for the "current weight". Instead, you use the CSS-wide inherit
keyword to inherit the weight from the parent element (the element that contains the so-called "surrounding text" along with the element in question):
strong { font-weight: inherit; text-transform: uppercase;}
header { font-weight: bold;}
<header> <h1>Header</h1> <p>This is a <strong>header</strong>.</p></header><footer> <p>This is a <strong>footer</strong>.</p></footer>
Why does font-weight: bolder skip boldness steps?
From the font-weight
section of the CSS2.1 specification:
Values of 'bolder' and 'lighter' indicate values relative to the weight of the parent element. Based on the inherited weight value, the weight used is calculated using the chart below. Child elements inherit the calculated weight, not a value of 'bolder' or 'lighter'.
Inherited val bolder lighter
100 400 100
200 400 100
300 400 100
400 700 100
500 700 100
600 900 400
700 900 400
800 900 700
900 900 700
This means that anything bolder
than a font-weight
of 400 is given a weight of 700, and anything bolder than a font-weight of 700 is given a weight of 900.
This is exactly what is happening in your JSFiddle demo.
Bolder
This is some text with weight 400. <!-- 400 -->
This text is one step bolder than above. <!-- bolder than 400 = 700 -->
This text is one step bolder than above. <!-- bolder than 700 = 900 -->
This text is one step bolder than above. <!-- bolder than 900 = 900 -->
This text is one step bolder than above. <!-- ... -->
Lighter
This is some text with weight 400. <!-- 400 -->
This text is one step lighter than above. <!-- lighter than 400 = 100 -->
This text is one step lighter than above. <!-- lighter than 100 = 100 -->
This text is one step lighter than above. <!-- ... -->
What is a situation where the CSS bolder can be used properly?
font-weight: bolder
is used to set the next level of boldness above the base weight. This is useful if you are already using a bold font, but the font family supports a bolder weight. For example Open Sans
(https://fonts.google.com/specimen/Open+Sans) supports 10 weights. If your base font is Open Sans Bold
font-weight: bolder
will kick it up to Open Sans Extra-Bold
if it's available. Or if you are using light
it will kick it up to normal, etc.
Here's a fiddle that shows one example in practice:
https://jsfiddle.net/zv03Lf5v/3/
@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800');
p { font-family: 'Open Sans'; font-weight: bold; font-size: 36px;}
p span { font-weight: bolder}
p.lighter { font-weight: 200;}
<p> Open Sans <span>Bolder</span></p>
<p class="lighter"> Open San Light <span>Bolder</span></p>
How to choose font different font-weight? use bolder one or just font-weight?
You would use the latter, like this:
font-family: helvetica;
font-weight: bold;
or you can use this:
font-weight: bold;
Note, you likely should include more fonts, as not all browsers will render helvetica, so you could use something like this:
font-family: Helvetica,Arial,sans-serif;
Edit to match the above edit:
he values you can use are normal
(which is the default weight), bold
, bolder
, lighter
. You can also use the values from 100 to 900, the higher being bolder. You can also use initial
and inherit
.
Note font-weight should work fine with Chinese; the fonts themselves are the ones you need to pay attention to.
Font-weight less than 400 on inputs
input
elements (and others like textarea
, etc.) do not inherit font from the parent element. They have their own default fonts.
If you change your CSS selector to html, input
, you can see it has the appropriate font weight in all inputs.
Why are THs bolder than TDs and how to avoid it?
I checked your code snippet both in Firefox and Internet Explorer (latest versions) and indeed, there is a difference in how the boldness of the th
elements is rendered by the two browsers.
The best explanation that I can offer is that the CSS specification does not say anything about how the font-weight of the th
elements is to be computed, so how this is to be done is left up to the browser.
In both browsers, if you specify the font-weight on the td
and th
elements explicitly as in your Table B, then you get a consistent font-weight. In Firefox, the value is set to bold
and in Internet Explorer, the bold
value is mapped to the font-weight scale value 700
for the Arial font.
In the case of Table A, the font-weight is applied to the parent element, the tr
that contains the table cells. In the case of Firefox, the CSS engine inherits the value from tr
, that is bold
, and you get the consistent font-weight.
However, for Internet Explorer, font weights are computed differently. First, the IE CSS engine gets the inherited value, bold
, and applies it to the td
elements as a font-weight of 700
. For the th
element, the IE CSS engine appears to apply the equivalent of bolder
instead of bold
, and this leads to a computed font-weight of 900
, which makes the th
elements look bolder.
What you are seeing here is a cross-browser difference due to how the software design engineers decided to interpret the CSS specification in a case where there were no explicit guidelines as to what to do.
I also noticed that if you change the font-family to something else, you may not see the problem, since browsers read font meta data to decide how to map the font-weight scale to the font-weights indicated in the font meta data.
(See http://dev.w3.org/csswg/css2/fonts.html#font-boldness for some indication of what the CSS engines may be doing in the background.)
As for a fix, well you more or less have it already. Specify the font-weight explicitly by selecting td
and th
elements directly.
table.a tr { font: bold 12pt Arial;}table.b td, table.b th { font: bold 12pt Arial;}
<h2>Boldness Check</h2>
<table class="a"> <tr> <th>TH Column 1</th> <td>TD Column 2</td> <th>TH Column 3</th> </tr></table><table class="b"> <tr> <th>TH Column 1</th> <td>TD Column 2</td> <th>TH Column 3</th> </tr></table>
Adjusting font-weight:bold
There are many many many fonts that look like Arial that you can play with , some are bolder then others ,
Try looking for a font In Google WebFonts and you can attach it into your css to ensure it will work in every browser
Related Topics
How to Remove HTML5 Video Player Navigation Button
Why Does My Flexbox Sticky Footer Not Work in Safari
How to Use Tick/Checkmark Symbol (✓) Instead of Bullets in Unordered List
Prevent Linebreak After </Div>
How to Use Div Class and Id Together in CSS
Why Do My Icons Line Up Top-To-Bottom Instead of Flowing Left-To-Right in a Div Layout
Angular2 Sub Component Break CSS Relationship
Make an Image to Fit Its Parent Dimensions
How to Customize Only with CSS for HTML5 Input Range Slider-Vertical
How to Make a Div with a Rails Link Clickable
How to Set The Current Frame (Or Similar) of a CSS Animation
How to Center Images in a Responsive Grid with CSS Only and Supporting Retina Displays
CSS Text Replace with Image, Need Hyperlink
How to Set This Div to Be The Minimum Possible Width to Display Its Floating Contents
HTML5 Video Background, Keep Center of Video in Center
Center Div Vertically in Flexbox Container with Stretch Alignment