Padding是比较常用CSS样式,我们可以利用padding样式来设置内边距,下面我们从基础语法到应用示范最后举一个小列子来给大家说一下padding样式如何使用,
padding语法结构与说明
padding : +数值+单位 或 百分比数值
div{padding:5px}设置对象距离四边边距为5px间隔
同时可以单独设置左、右、上、下边距离发布设置
1、padding-left 设置对象距离左边的边距补白间隔
div{padding-left:5px}
对象内距离左边补白间距为5px
2、padding-right 设置对象距离右边的边距补白间隔
div{padding-right:5px}
对象内距离右边补白间距为5px
3、padding-top 设置对象距离上边的边距补白间隔
div{padding-top:5px}
对象内距离上边补白间距为5px
4、padding-bottom 设置对象距离下边的边距补白间隔
div{padding-bottom:5px}
对象内距离下边补白间距为5px
div css Padding说明
检索或设置对象四边的补丁边距。
如果提供全部四个参数值,将按上-右-下-左的顺序作用于四边。
如果只提供一个,将用于全部的四条边。
如果提供两个,第一个用于上-下,第二个用于左-右。
如果提供三个,第一个用于上,第二个用于左-右,第三个用于下。
内联对象要使用该属性,必须先设定对象的height或width属性,或者设定position属性为absolute。
Padding的值不能为负值。
Padding位于对象(边框)以内,或这样说padding样式是位于对象内的内容区域与边框之间。
padding设置四边用法案例
为了对padding用法进一步了解,我们设置一个对象分别设置4边不同的padding补白间距,并且设置对象CSS宽度,css 高度、CSS边框属性样式。为了便于观察padding存在,我们设置padding-left(左)为20px,padding-right(右)为30px,padding-top(上)为40px,padding-bottom(下)为50px。
1、padding案例CSS代码
.div{ width:350px; height:80px; border:1px solid #00F;
padding-left:20px;padding-right:30px;padding-top:40px;padding-bottom:50px}
2、案例HTML代码
4. Case summary
padding is used to set the style of the distance from the four-sided border within the object to the content area, so to achieve spacing within the object, you can use css div + padding.
3. Padding abbreviation and case
#1. The four sides are the same. The padding abbreviation
If the padding setting value is the same on the four sides, if it is 5px, Original expression:
padding-left:5px;padding-right:5px;padding-top:5px;padding-bottom:5px;
can be abbreviated in CSS as:
padding:5px;
2. The abbreviation of different padding on the four sides
Just like the different padding values on the four sides in our second tutorial, padding-left:20px;padding-right:30px;padding- top:40px;padding-bottom:50px
We can abbreviate it as:
Padding:40px 30px 50px 20px;
Note that each value is separated by a space
Explain the meaning
The first 40px represents "top" padding-top:40px;
The second 30px represents "right" padding-right:30px;
The third 50px represents "bottom" padding-bottom:50px;
The fourth 20px represents "left" padding-left:20px;
3. The left and right sides are the same, top and bottom Abbreviations for padding with different values
If padding is 10px on the left and right, 20px on the top, and 30px on the bottom
General writing method:
padding-left:10px;padding-right:10px; padding-top:20px;padding-bottom:30px
The abbreviation can be:
Padding:20px 10px 30px;
The former first 20px represents the padding-top. 20px,
The second 10px represents padding-left and padding-right of 10px
The third 30px represents padding-bottom: 30px
4. Three sides Same, but one side has different values
If any three sides have the same value, but the other sides are different, we can still abbreviate it.
EXP
If the padding is 10px on the top and left and 20px on the bottom, the CSS style is generally written like this
padding-left:10px;padding-right:10px;padding -top:10px;padding-bottom:20px
The abbreviation is:
padding:10px;padding-bottom:20px
Note that the order cannot be reversed. The trick here is to browse The reader reads from top to bottom and from left to right, so we can first set the four sides to be the same, and then add a different style value for the other side.
Extended reading:
1.html compression optimization
2.css compression optimization
3.css optimization
4.css Word spacing
padding css summary
Padding style is a CSS style attribute that we use more frequently. Generally, we use padding to set the upper, lower, left, and right margin intervals within an object. Of course, if we encounter the indentation of the beginning text, we can use the css text-indent style. When using padding, pay attention to the increase or decrease in width. Padding takes up the width and height. If the total width is 500px, and a 10px padding style is set on the left and right, the width of the content area will become 480px. At the same time, pay attention to the meaning of the abbreviation PADDING when using the style. Try to use CSS abbreviations like
There are so many ways to use padding. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to set paragraph line height and line spacing in HTML
How to write html document type declaration
The above is the detailed content of How to use padding attribute in css. For more information, please follow other related articles on the PHP Chinese website!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 English version
Recommended: Win version, supports code prompts!
