search
HomeWeb Front-endHTML TutorialDIV CSS padding inner padding (padding) left right top bottom_html/css_WEB-ITnose

DIV CSS padding内补白(内边距)left right top bottom语法应用案例教程

Padding是比较常用CSS样式,可以利用padding内边距设置上、下、左、右对象内容与四个边距距离间隔。接下来DIVCSS5从基础语法到应用示范、简写用法讲解CSS padding样式。

一、padding语法结构与说明   -   TOP

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设置四边用法案例   -   TOP

为了对padding用法进一步了解,我们设置一个对象分别设置4边不同的padding补白间距,并且设置对象CSS宽度,css 高度、CSS边框属性样式。为了便于观察padding存在,我们设置padding-left(左)为20px,padding-right(右)为30px,padding-top(上)为40px,padding-bottom(下)为50px。

1、padding案例CSS代码

 

2、案例HTML代码

DIVCSS5 padding使用案例

3. Screenshots of padding usage application cases

Padding case illustration screenshots of padding usage demonstration in the software

Actual effect in browser:

Padding application browser test Result image

4. Case summary

padding is used to set the style of the spacing between the four-sided border and the content area within the object, so to achieve spacing within the object, you can use css div padding.

3. Padding abbreviation and cases - TOP

1. The four sides are the same and the padding abbreviation is the same. If the padding setting value is the same on the four sides, if it is 5px, the original expression is: 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 is 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;

Graphic description padding abbreviation

Padding optimization abbreviation analysis chart

3. The left and right are the same, but the top and bottom are different The value padding abbreviation is if the padding left and right is 10px, the top is 20px, and the bottom is 30px

Generally written: padding-left:10px;padding-right:10px;padding-top:20px;padding-bottom:30px

The abbreviation can be: Padding:20px 10px 30px;

The first 20px in the former represents 20px on padding-top, and the second 10px represents 10px on padding-left and padding-right. Three 30px represents padding-bottom: 30px

4. Three sides are the same, but one side has a different value. If any three sides have the same value, and the other side is 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 that the browser reads from top to bottom and from left to right, so we can first set the four sides to be the same , then add a different style value on the other side.

Extended reading: 1. HTML compression optimization 2. CSS compression optimization 3. CSS optimization 4. CSS word spacing

4. Padding css summary - TOP

Padding style is the one we use more frequently CSS style attributes. Generally, we use padding to set the upper, lower, left, and right margin intervals within an object. Of course, if we encounter 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 style, and try to use CSS abbreviation style to save CSS code. Simple example of css padding.

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
HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

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

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.