How do I create padding in CSS?

CSS Padding allows HTML to set default padding or dead space outside the HTML element. The advantage of this is that it saves the encoder in the repetition of this padding code for each instance of this element and makes it easier to create consistency on the page. The element of HTML to be padded can be any number of things such as paragraph, table or headline.

You want to create padding in CSS, first you will need to identify the element of HTML you want to serve. This element you want to serve is known as a selector. You will then want to enter the appropriate padding values. There are five different types of padding in CSS - one for all four sides of the element at the same time and four more for each individual side of the element (eg left side, right side, upper side or underside). The property that allows the programmer to enter values ​​for all four sides of the HTML element at once is called the abbreviation .

coding language used to determine one declarationRace padding CSS is simply the word "padding". After this label, the appropriate "values" of padding or information about the amount of space desired are usually represented by either pixels or percentage. Padding and values ​​are written inside curly braces or curly brackets (ie "{" and "}"). The previous one is an element of HTML to be padded (eg "P" for paragraph or "H2" for level 2 headers).

As far as the value is represented, the values ​​can be represented in pixels (eg 1px or 5px), points (eg 1pt or 5PT) or inch (eg 1in or 5in) or centimeters (eg 1cm or 5 cm). The values ​​can also be declared as a percentage of HTML element. For example, if the value is 50%, the padding equals half the size of the element.

The following examples are the HTML code for HTML element padding according to values ​​reflecting in percent and length. If only one value is assigned, then web browsers assign this padding to allHNY Four Pages of HTML element.

padding: 10%;
Padding: 100px;

Adding multiple values ​​to the above type of padding will cause web browsers to interpret them in a certain way. If two values ​​are assigned, the first will correspond to the upper and lower parts, while the second corresponds to the left and right. Three values ​​cause the first to reference to the top, the second on the left and right side and the third to the bottom of the HTML element. Assigning a maximum of four values ​​will cause the first, second, third and fourth values ​​to correspond to the upper, right, lower and left element HTML in this order. If more than one value is provided, it should be separated by gaps and ended with half -circle, for example:

padding: 10px 20px 10px 20px;

CSS padding can be done on one side time. In this respect, four other padding properties are available. These are padding-tops, padding-right, padding bottom and left padding. You want to create a cushionCSS by marking the properties of the same syntax as the abbreviation declaration as mentioned above. Each of these padding properties has only one value or percentage. For example:

padding-top: 10px;
Padding-right: 20px;
Padding-Bottom: 10px;
Padding-Left: 20px;

The following code creates a website, declares the padding properties between styles marks, and then uses them in the paragraph designated by the P. Text between/ and */ are notes to explain the type of padding and would not be included in the CSS padding code.


​​

P.Example1 {Padding: 10px;} /* Short-Hand Padding for all four sides* /
P.Example2 {Padding: 50px 30px;} / * Short Padding on top and lower part followed by left and right * /
P.Example3 {
Padding-top: 10px;
Padding-Bottom: 20px;
Padding-Bottom: 10px;
Padding-Left: 20px;
} /* Individual padding. */




This text has the same padding on each side. Padding on each side is 10px.


This text has the upper and lower padding 50px and the left and right padding 30px.


This text has the highest padding 10px, right 20px padding, lower padding 10px and left padding 20px.



In the above example "Example1" etc. are names assigned to a class, which is then referred to in paragraphs. The period between the P and the names of the class at the beginning of the code indicates the statement of the class assigned by the paragraph. Notice braces after the Classation Claxing statement Placking Connection The Rank of Features.

Although it might seem like a lot of work, it is much less demanding to work than to determine the padding for each individual paragraph. For the desired element you can declare one padding feature that is in the aboveAn example of the P, and then refer to the class when using the element between the body marks on the page. If only one type of padding is needed for all paragraphs, you do not have to use courses at all. Simply use the following code between the style marks, and then encode the paragraph without entering any class. This code would go between the body marks instead of the code in the above example.

p {padding: 10px 20px 10px 20px;}

This CSS padding that would create would affect all paragraphs, even if no class was specified.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?