How to set the left margin in css: 1. Use the margin-left attribute to set the left margin of the element. The syntax format is "margin-left:margin value;"; 2. Use the padding-left attribute. You can set the left padding of the element with the syntax format "padding-left:margin value;".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
1. Use margin-left to set the left margin
The margin-left attribute sets the left margin of the element.
Note: Negative values are allowed.
Attribute value:
Value | Description |
---|---|
auto | The left margin set by the browser. |
length | Define 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. |
Example:
2. Use padding-left to set the left inner margin
Thepadding-left attribute sets the left padding of an element.
Note: Negative values are not allowed.
Attribute value:
Value | Description |
---|---|
length | Specifies a fixed left padding value in specific units, such as pixels, centimeters, etc. The default value is 0px. |
% | Defines a percentage left padding based on the width of the parent element. This value will not work as expected in all browsers. |
Example:
Learning video sharing:css video tutorial
The above is the detailed content of How to set left margin in css. For more information, please follow other related articles on the PHP Chinese website!