Home  >  Article  >  Web Front-end  >  How to add horizontal lines on both sides of text in css

How to add horizontal lines on both sides of text in css

青灯夜游
青灯夜游Original
2021-01-05 17:06:1811274browse

You can use the :before, :after and content attributes in css to add horizontal lines on both sides of the text; the syntax "E:before,E:after{content:"";flex:1 1;border-bottom :2px solid;}", E is an element containing text.

How to add horizontal lines on both sides of text in css

#The operating environment of this tutorial: Windows 7 system, css3 version, Dell G3 computer.

Tutorial recommendation: css video tutorial

css method of adding horizontal lines on both sides of text

In css, This can be achieved using the :before, :after selectors and the content attribute.

:The before selector inserts content before the selected element, and the :after selector inserts content after the selected element.

The content attribute is used with the :before and :after pseudo-elements to insert generated content.

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			h4 {
				display: flex;
				flex-direction: row;
			}
			
			h4:before,
			h4:after {
				content: "";
				flex: 1 1;
				border-bottom: 2px solid #000;
				margin: auto;
			}
			
			img {
				height: 100px;
				width: 100px;
				border-radius: 50%;
			}
		</style>
	</head>

	<body>
		<h4>PHP中文网</h4>
	</body>

</html>

Rendering:

How to add horizontal lines on both sides of text in css

##For more programming-related knowledge, please visit:

Programming Teaching ! !

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

Statement:
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