How to set padding in css

醉折花枝作酒筹
Release: 2023-01-05 16:10:28
Original
5872 people have browsed it

In CSS, you can use the padding attribute to set the padding. You only need to set "padding: value unit | percentage value" to the element. The padding property sets the width of all padding on an element, or sets the width of padding on each side. The padding attribute does not allow negative padding values to be specified.

How to set padding in css

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

Let’s take a look at how to set padding (padding):

Our padding is one of the css box models, so now let’s take a look at the padding How is it set up?

padding: is a shorthand attribute that can set all padding attributes in a declaration.

Use the padding attribute alone to change the top, bottom, left, and right padding.

Possible values:

length: Defines a fixed padding (pixels, pt, em, etc.)

%: Defines a padding using a percentage value

Usage:

padding-left sets the padding spacing from the left side of the object

div{padding-left:5px}
Copy after login

The padding spacing from the left side within the object is 5px

padding-right sets the padding spacing on the right side of the object

div{padding-right:5px}
Copy after login

The padding spacing on the right side of the object is 5px

padding-top sets the distance on the object The top margin padding interval

div{padding-top:5px}
Copy after login

The distance between the top padding within the object and the top padding distance is 5px

padding-bottom sets the distance between the object and the bottom padding

div{padding-bottom:5px}
Copy after login

The inner distance between the object and the bottom padding spacing is 5px

Description

Retrieve or set the patch margins on the four sides of the object.

If all four parameter values are provided, the four sides will be applied in the order of top-right-bottom-left.

If only one is provided, it will be used for all four edges.

If two are provided, the first one is used for up-down, and the second one is used for left-right.

If three are provided, the first is for up, the second is for left-right, and the third is for bottom.

To use this attribute on an inline object, you must first set the height or width attribute of the object, or set the position attribute to absolute.

The value of Padding cannot be negative.

Example:

     
padding用法
Copy after login

Rendering:

How to set padding in css

Recommended learning:css video tutorial

The above is the detailed content of How to set padding 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!