How to clear the p tag's own spacing in css

青灯夜游
Release: 2021-11-09 11:44:51
Original
5065 people have browsed it

In css, you can clear it by setting the "p {padding:0;margin: 0;-webkit-margin-before: 0;-webkit-margin-after: 0;}" style to the p tag The spacing of the p tag itself.

How to clear the p tag's own spacing in css

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

In HTML, each tag has a default style. For example, the p tag itself has spacing:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
p {
border: 1px solid red;
}
</style>
</head>
<body>
<p>hello</p>
<p>hello</p>
</body>
</html>
Copy after login

How to clear the p tags own spacing in css

So how to remove the spacing of the p tag itself?

We can use the margin and padding attributes and set their values ​​​​to 0:

p {
	padding:0;
	margin: 0;
}
Copy after login

In this way, the p tag's own spacing can be cleared:

How to clear the p tags own spacing in css

But in some browsers, even so, there are still top and bottom margins, because

How to clear the p tags own spacing in css

here-webkit-margin-after and -webkit-margin-before both have 1rem, so it is best to set both of them to 0

-webkit-margin-before: 0;
-webkit-margin-after: 0;
Copy after login

(Learning video sharing: css video tutorial

The above is the detailed content of How to clear the p tag's own spacing 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