CSS ช่วยให้เราสามารถตั้งค่าการเติมเฉพาะด้านสำหรับองค์ประกอบ คุณสมบัติ padding-top, padding-right, padding-bottom และ padding-right กำหนดช่องว่างด้านบนขวาด้านล่างและด้านซ้ายตามลำดับ คุณสมบัติชวเลขช่องว่างภายในยังสามารถใช้เพื่อให้ได้ผลลัพธ์เดียวกันโดยการระบุค่าในทิศทางตามเข็มนาฬิกา
ไวยากรณ์
ไวยากรณ์ของคุณสมบัติการเติม CSS มีดังต่อไปนี้ -
Selector {
padding-top: /*value*/
padding-right: /*value*/
padding-bottom: /*value*/
padding-left: /*value*/
} ตัวอย่างต่อไปนี้แสดงให้เห็นถึงการจัดรูปแบบรายการ -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
article {
margin: 2em 1em;
padding: 3%;
background-color: plum;
letter-spacing: 0.05em;
}
span {
padding: 0 53%;
border-right: dashed;
background-image: linear-gradient(to right, lavenderblush, lightblue);
font-size: 1.4em;
font-style: italic;
}
</style>
</head>
<body>
<h2>What is Xamarin?</h2>
<article>
<span>Xamarin is a software company based in San Francisco. Xamarin is built on the .NET Framework.</span> It provides commercial software development tools that allow a user to develop applications for Android, iOS and Windows using C# language and the .NET framework.
</article>
</body>
</html> ผลลัพธ์

ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
div {
max-width: 400px;
padding-left: 30px;
padding-top: 44px;
padding-bottom: 60px;
background-image: linear-gradient(to bottom, oldlace, lightblue);
border: thin solid;
text-align: center;
}
div > div {
padding-right: 70px;
}
</style>
</head>
<body>
<h2>Swift programming language by Apple</h2>
<div>Swift is a programming language developed by Apple Inc for iOS and OS X development.
<div>Swift 4 uses the same runtime as the existing Obj-C system on Mac OS and iOS, which enables Swift 4 programs to run on many existing iOS 6 and OS X 10.8 platforms.
</div>
</div>
</body>
</html> ผลลัพธ์
