Padding ng CSS
- Previous Page Pagkakasama ng Margin ng CSS
- Next Page CSS Height/Width
Padding ng CSS
CSS padding
Ang katangian na ito ay ginagamit para lumikha ng espasyo sa paligid ng nilalaman ng elemento sa anumang naipinalagay na hangganan.
Sa pamamagitan ng CSS, maaari mong lubusang kontrolin ang panig-pangpanig (pad). Mayroong ilang katangian na maaaring itakda ang panig-pangpanig para sa bawat gilid ng elemento (taas, kanan, pababa at kaliwa).
Padding - Isang gilid
CSS ay may mga katangian na magbibigay ng panig-pangpanig para sa bawat gilid ng elemento:
padding-top
padding-right
padding-bottom
padding-left
Ang lahat ng panig-pangpanig na katangian ay maaaring magkaroon ng mga sumusunod na halaga:
- length - Tumutukoy sa panig-pangpanig gamit ang mga yunit tulad ng px, pt, cm at iba pa
- % - Tumutukoy sa porsyento ng lapad ng kasalukuyang elemento
- inherit - Tumutukoy na ang panig-pangpanig ay magsisimula sa magulang na elemento
Mga payo:Hindi pinapayagan ang mga negatibong halaga.
Example
Para sa lahat ng apat na gilid ng elemento <div> na magkaroon ng iba't ibang panig-pangpanig:
div { padding-top: 50px; padding-right: 30px; padding-bottom: 50px; padding-left: 80px; }
Padding - Mga pangalawang pangalan ng katangian
Para mai-kabawian ang kodigo, maaring ilagay ang lahat ng panig-pangpanig sa isang katangian.
padding
属性是以下各内边距属性的简写属性:
padding-top
padding-right
padding-bottom
padding-left
工作原理是这样的:
If padding
属性有四个值:
- The left inner padding is 100px, and the right inner padding is 50px
- padding: 25px 50px 75px 100px;
- The attribute is a shorthand for the following inner padding properties:
- The attribute sets three values:
- How it works:
Example
The attribute has four values:
div { The left inner padding is 100px, and the right inner padding is 50px }
If padding
Use a shorthand attribute for padding that sets four values:
- Use a shorthand attribute for padding that sets three values:
- padding: 25px 50px 75px 100px;
- The right and left inner paddings are 50px, and the top and bottom inner paddings are 25px
- The attribute sets three values:
Example
The bottom inner padding is 75px, and the top inner padding is 25px
div { Use a shorthand attribute for padding that sets three values: }
If padding
padding: 25px 50px 75px;
- padding: 25px 50px;
- The attribute sets two values:
- The right and left inner paddings are 50px, and the top and bottom inner paddings are 25px
Example
Use a shorthand attribute for padding that sets two values:
div { padding: 25px 50px; }
If padding
The attribute sets a value:
- padding: 25px;
- All four inner paddings are 25px
Example
Use a shorthand attribute for padding that sets a value:
div { padding: 25px; }
Inner padding and element width
CSS width
The width property specifies the width of the element's content area. The content area is the part within the element (box model) that is inside the padding, border, and margin.
Therefore, if an element has a specified width, the padding added to the element will be added to the total width of the element. This is usually not the desired result.
Example
Here, the width of the <div> element is 300px. However, the actual width of the <div> element will be 350px (300px + left padding 25px + right padding 25px):
div { width: 300px; padding: 25px; }
To keep the width at 300px regardless of the padding, you can use box-sizing
This will cause the element to maintain its width. If the padding is increased, the available content space will decrease.
Example
Use the box-sizing attribute to keep the width at 300px regardless of the padding:
div { width: 300px; padding: 25px; box-sizing: border-box; }
More examples
- Set left inner padding
- This example demonstrates how to set the left inner padding of the <p> element.
- Set right inner padding
- This example demonstrates how to set the right inner padding of the <p> element.
- Set top inner padding
- This example demonstrates how to set the top inner padding of the <p> element.
- Set bottom inner padding
- This example demonstrates how to set the bottom inner padding of the <p> element.
All CSS inner padding properties
Property | Description |
---|---|
padding | A shorthand attribute used to set all inner padding properties in one declaration. |
padding-bottom | Set the bottom inner padding of the element. |
padding-left | Set the left inner padding of the element. |
padding-right | Set the right inner padding of the element. |
padding-top | Set the top inner padding of the element. |
Further Reading
Supplement:Box Model: CSS Padding
- Previous Page Pagkakasama ng Margin ng CSS
- Next Page CSS Height/Width