In CSS, the padding property allows us to add extra space between the border of an HTML element and its content. Right padding means only adding space between the element content and the right border.
Here we will learn two different properties to specify the right padding of an element.
Use padding-right CSS property
The ‘padding-right’ property specifies the right padding of an element in CSS. Whenever we specify right padding for an element, the width of that element is equal to the actual width of the right padding.
grammar
Users can specify the right padding of elements according to the following syntax.
padding-right: 100px;
Example 1
In the example below, the parent div contains multiple child divs. Using the "padding-right" CSS property, we specify a right padding of "300px" for the parent div. Additionally, we specify a padding-right of 100px for all child div elements.
In the output, the user can observe that there is 300px space between the right border and the child div. Additionally, there is 100px of free space between the right border and the text content.
<html> <style> .parent { width: 300px; height: 400px; border: 2px solid red; padding-right: 300px; display: flex; flex-wrap: wrap; } .child { width: 200px; height: 100px; border: 2px solid green; padding-right: 100px; } </style> <body> <h3 id="Using-the-i-padding-right-CSS-property-i-to-add-the-padding-at-right-in-the-HTML-element">Using the <i> padding-right CSS property </i> to add the padding at right in the HTML element.</h3> <div class = "parent"> <div class = "child"> This is a child div. </div> <div class = "child"> This is a child div. </div> <div class = "child"> This is a child div. </div> </div> </body> </html>
Example 2
In the example below, we create a card component and add an image to it. Additionally, we've given the card div a right padding of 10px. In the output, the user can observe a 10px space on the right.
<html> <style> .card { width: 520px; height: 100px; background-color: grey; padding-right: 10px; } </style> <body> <h3 id="Using-the-i-padding-right-CSS-property-i-to-add-the-padding-at-right-in-the-HTML-element">Using the <i> padding-right CSS property </i> to add the padding at right in the HTML element.</h3> <div class = "card"> <img src = "https://www.tutorialspoint.com/images/logo.png" alt = ""> </div> </body> </html>
Using CSS Fill Properties
The padding property is used to set the padding on all four sides of an element. We can set the right padding to a value and the other sides to 0. The first value represents the top, the second represents the right, the third represents the bottom, and the fourth represents the left. So we're going to keep 0 as the value except for the second value.
grammar
Users can use the padding CSS property to specify the right padding of an element according to the following syntax.
padding: 0 value 0 0;
Example 3
In the example below, we have added a card div and added some text inside the container div. Additionally, we are giving "5rem" padding on the right side of the container div element. The user can observe the 5rem spacing between the right border of the container div and its content.
<html> <style> .container { width: 10rem; height: 10rem; background-color: #f08a8a; padding: 0 5rem 0 0; } </style> <body> <h3 id="Using-the-i-padding-CSS-property-i-to-add-the-padding-at-right-in-the-HTML-element">Using the <i> padding CSS property </i> to add the padding at right in the HTML element.</h3> <div class = "container"> <div class = "card"> <h3 id="This-is-a-card-inside-the-container-div-The-right-padding-is-rem">This is a card inside the container div. The right padding is 2rem.</h3> </div> </div> </body> </html>
Users learn to specify correct padding for HTML elements, and they can use the "padding-right" or "padding" CSS properties. If we use the padding attribute, we only need to specify the second value and leave the other values at 0.
The above is the detailed content of Which property in CSS specifies the right padding of an element?. For more information, please follow other related articles on the PHP Chinese website!

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,


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

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.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools