Home > Web Front-end > CSS Tutorial > How to add spaces in css

How to add spaces in css

青灯夜游
Release: 2021-07-14 16:14:50
Original
9854 people have browsed it

In CSS, you can use the pseudo-elements ":before" and ":after" to add spaces before or after the element content. The syntax format is "element:before {content: " ";}" or "Element:after {content: " ";}".

How to add spaces in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can use the pseudo-elements ":before" and ":after" to add spaces before or after the element content.

:The before selector inserts content before the content of the selected element; the :after selector inserts content after the content of the selected element.

The inserted content needs to be specified using the content attribute.

Grammar format:

// 在元素的内容前面插入内容
:after {
    content:"值";
}

// 在元素的内容后面插入内容
:after {
    content:"值";
}
Copy after login

Example: Insert spaces

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>在选定的元素前或后添加空格</title>
		<style>
			h2 {
				text-decoration: underline;
			}

			h2.before:before {
				content: " ";
				white-space: pre;
			}

			h2.after:after {
				content: " ";
				white-space: pre;
			}
		</style>
	</head>

	<body>
		<h2>元素内容:</h2>
		<h2 class="before">元素内容:</h2>
		<h2 class="after">元素内容:</h2>
	</body>
</html>
Copy after login

Rendering:

How to add spaces in css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to add spaces in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template