Home  >  Article  >  Web Front-end  >  How to set the left margin to disappear in css

How to set the left margin to disappear in css

WBOY
WBOYOriginal
2022-09-05 16:37:191589browse

How to set the left margin to disappear in css: 1. Use the "margin-left" attribute, which is used to set the left margin of the element. The syntax is "margin-left:0;"; 2. Use " padding-left" attribute, which can set the left padding of the element, that is, the left inner margin. The syntax is "padding-left:0;".

How to set the left margin to disappear in css

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

How to set the left margin to disappear in css

The margin-left attribute sets the left margin of the element.

  • #auto The left margin set by the browser.

  • #length defines a fixed left margin. The default value is 0.

  • % Defines the left margin as a percentage based on the total width of the parent object.

padding-left attribute sets the left padding (space) of an element

  • length is specified in specific units Fixed left padding value, such as pixels, centimeters, etc. The default value is 0px.

  • % Defines the left padding as a percentage based on the width of the parent element. This value will not work as expected in all browsers.

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>123</title> 
<style>
p.ex1 {margin-left:2cm;}
p.ex2 {margin-left:0;}
p.ex3 {padding-left:2cm;}
p.ex4 {padding-left:0;}
</style>
</head>
<body>
<p class="ex1">一个左外边距为2厘米的段落。</p>
<p class="ex2">一个没有指定边距大小的段落。</p>
<p class="ex3">一个左内边距为2厘米的段落。</p>
<p class="ex4">一个没有指定边距大小的段落。</p>
</body>
</html>

Output result:

How to set the left margin to disappear in css

(Learning video sharing: css video Tutorial,html video tutorial)

The above is the detailed content of How to set the left margin to disappear 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