Home Web Front-end CSS Tutorial Detailed explanation of usage examples of font-weight attribute in css

Detailed explanation of usage examples of font-weight attribute in css

Jul 21, 2017 am 09:12 AM
css

To understand how the user agent determines the thickness of the font deformation, we must first talk about keywords 100 to 900, and then we will look at how it is inherited.

font-weight allowed values ​​normal | bold | bolder | lighter | l00 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900

These numeric keywords are used to define and The mapping relationship of the related characteristics of the font, that is, the thickness of the font is divided into nine levels. For example, OpenType uses a nine-value numeric level. After the font has this level, these numbers are mapped directly to each level, such as 100 mapping to the lightest font distortion, and 900 corresponding to the heaviest font distortion.

In fact, there is no essential font weight convention in these numbers. CSS states that the font weight corresponding to each number must not be smaller than the font weight corresponding to the number before it.

In this way, 100, 200, 300 and 400 may all correspond to font deformations of the same thickness, while 500 and 600 may correspond to a thicker font deformation, and 700, 800 and 900 may correspond to another thicker font deformation. Bold font distortion.

This number is defined as the same as some ordinary, and 700 corresponds to bold.

Font deformation names are equivalent. 400 is equivalent to normal

Other numbers do not correspond to any

font-weight attribute keywords, but they can correspond to ordinary font deformation names. If a font variant is tagged "Normal", "Regular", "Roman", or "Book", then it is assigned 400, and any font variant tagged "Medium" is assigned 500.

However, if the font variant marked "Medium" is the only available font, then it cannot correspond to 500.

If there are fewer than nine font weights in a given font family, the user agent has more work to do. In this case, it must fill the gaps in a predefined way:

If the value 500 is not assigned, it is given the same font weight as 400.

If 300 is not allocated, it corresponds to a slightly lighter font variant than 400. If no lighter font is available, 300 corresponds to a grade just like 400. This is usually in the "Normal" and "Medium" cases. The same method is used for 100 and 200.

If 600 is not allocated, it corresponds to a slightly heavier font variant than 400. If no such font is available, 600 corresponds to a certain font variant just like 500. This method is also used on the 700, 800 and 900.

For ease of understanding, let us look at three

examples of font weight allocation. First, assume that the font family Karrank% is an OpenType font, and 9 corresponding weight levels have been defined.

Here, these numbers correspond to each level, and the keywords normal and bold are assigned to 400 and 700 respectively. In the second example, we consider the font family Zurich, which was mentioned at the beginning of this article. Assume that its font variant is also assigned the weight value below.

Font form: Zurich Light Assigned keywords: empty Assigned numbers: 100,200,300

Font form: Zurich Regular Assigned keywords: normal Assigned numbers: 400

Font form: Zurich Medium Assigned keyword: empty Assigned number: 500

Font form: Zurich Bold Assigned keyword: bold Assigned number: 600,700

Font form: Zurich Black Assigned Keyword: empty Number assigned: 800

Font style: Zurich UltraBlack Keyword assigned: empty Number assigned: 900

The first three numbers are assigned to the lightest font. Normal fonts correspond to keywords 400 and normal.

Medium font is assigned to the number 500. There is no font variant assigned to 600, so 600 and 700 together correspond to the same font variant Bold font. Finally, 800 and 900 are allocated to Black and UltraBlack font variants respectively.

This situation will only occur when the top two thickness levels have been allocated.

Otherwise the user agent may ignore them and assign 800 and 900 to the Bold font, or assign them to one of the two Black font variants. Finally, let's look at the Times font, which has only two font variants, TimesRegulal and TimesBold, as shown below.

Font form: TimesRegular Assigned keywords: normal Assigned numbers: 100,200,300,400,500

Font form: TimesBold Assigned keywords: bold Assigned numbers: 600,700,800,900

Key words The assignment of normal and bold is fairly straightforward. For these numbers, 100 to 300 are assigned to the Regular font, but what about 500? It is assigned to the Regular font because there is no Medium font; so it is the same as 400.

Of the remainder, 700 is always assigned to the bold font, while 800 and 900, due to the lack of bolder fonts, are also assigned to the bold font. Finally, 600 is allocated to the next

Bolder font, of course, only bold font.

The font weight can be inherited. If the paragraph is set to bold, all child elements will inherit the bold font, as follows:

p.one {
  font-weight:bold; }
Copy after login

The above is the detailed content of Detailed explanation of usage examples of font-weight attribute in css. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles