Home >Web Front-end >CSS Tutorial >Which property in CSS specifies the right padding of an element?
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.
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.
Users can specify the right padding of elements according to the following syntax.
padding-right: 100px;
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>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>
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>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>
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.
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;
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>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>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!