Home Web Front-end CSS Tutorial Comprehensive understanding of the usage instructions of css line-height

Comprehensive understanding of the usage instructions of css line-height

Mar 08, 2017 pm 02:53 PM

Introduction to this article: "Line height" refers to the height of a line of text, specifically the distance between the baselines between two lines of text. In CSS, line-height is used to control the vertical distance between lines. The line-height attribute affects the layout of line boxes. When applied to a block-level element, it defines the minimum distance between baselines in that element rather than the maximum distance. All browsers support the line-height property.

1. Line-height syntax

The specific definition list of line-height attribute is as follows:

Syntax: line-height: normal | | | | inherit

Description: line-height attribute Set the distance between rows (row height), negative values ​​cannot be used. This property affects the layout of the line box. When applied to a block-level element, it defines the minimum distance between baselines in that element rather than the maximum distance. The calculated difference between line-height and font-size (line spacing) is divided into two halves and added to the top and bottom of a line of text. The smallest box that can contain this content is a line box.

Possible values:


normalDefault, set reasonable line spacing. numberSet a number, which will be multiplied length to set a fixed line spacing. %Percent line spacing based on the current font size. inheritSpecifies that the value of the line-height attribute should be inherited from the parent element.


2. Examples of top line, middle line, baseline and bottom line in line-height

Illustration

Comprehensive understanding of the usage instructions of css line-height

The four lines from top to bottom are the top line, the middle line, the baseline, and the bottom line. They are very similar to the four lines and three grids used when learning English letters. We know that the vertical-align attributes include top, middle, baseline, and bottom, which are related to these four lines.

Remember especially that the baseline is not the bottom line, the bottom line is the bottom line.

3. Line-heightLine height, line spacing and half-line spacing

Line height refers to the context line The vertical distance between the baselines, that is, the vertical distance between the two red lines in the figure.

Line spacing refers to the vertical distance from the bottom line of one row to the top line of the next row, that is, the vertical distance between the pink line of the first row and the green line of the second row.

Half line spacing is half of the line spacing, that is, the vertical distance of area 3/2, the sum of the distances of areas 1, 2, 3, and 4 is the line height, and the sum of the distances of areas 1, 2, and 4 is the font size , so half line spacing can also be calculated like this: (line height - font size)/2

Picture Description

Comprehensive understanding of the usage instructions of css line-height

4. Content area, inline box, line box in line-height

##Content area: Wrapped by the bottom line and the top line area, which is the dark gray background area in the figure below.

Comprehensive understanding of the usage instructions of css line-height

Inline box, each inline element will generate an inline box. The inline box is a concept in the browser rendering model and cannot be displayed. , when there are no other factors (padding, etc.), the inline box is equal to the content area, and when the line height is set, the height of the inline box remains unchanged, and the half line spacing [(line height-font size)/2] increases/decreases to the content respectively. The upper and lower sides of the area (dark blue area)

Line box (line box), The line box refers to a virtual rectangular box of this line, which is a concept in the browser rendering mode , and is not actually displayed. The height of the line box is equal to the largest value of the inline box among all elements in this line (the inline box with the largest line height value is used as the benchmark, and other inline boxes are aligned to the benchmark using their own alignment methods, and the height of the line box is finally calculated). When there are multiple lines content, each line will have its own line box.

For example

Picture description

Comprehensive understanding of the usage instructions of css line-height

##5. How to define line-height1. Line-height can be defined as normal.

body { line-height:normal; }

2. Line-height can be defined as inheritance

p { line-height:inherit; }

3. Line-height can use a percentage value

p { line-height:120%; }

4. Line-height can be defined as a length value (unit px , em, etc.)

p { line-height:20px; }

5. Line-height can also be defined as a pure number (even without units)

p { line-height:1.2; }

The above is the comprehensive understanding of the usage of css line-height brought by the editor. I hope everyone will support the PHP Chinese website

##Value Description
by the current font size to set the line spacing. Equivalent to a multiple of

The above is the detailed content of Comprehensive understanding of the usage instructions of css line-height. 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)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there's a bit of a learning curve, but Grid is

See all articles