How to use padding in CSS
Thispadding
CSS properties are usually used in CSS to add space inside elements.
remember:
margin
Add space outside the element boundarypadding
Add space inside the element border
Specific fill properties
padding
With 4 related attributes, the padding of a single edge can be changed at the same time:
padding-top
padding-right
padding-bottom
padding-left
The usage of these is very simple and should not be confused, for example:
padding-left: 30px;
padding-right: 3em;
usepadding
shorthand
padding
It is an abbreviation for specifying multiple fill values at the same time, and its behavior will vary depending on the number of values entered.
1 value
Use a single value to apply it toAllFiller: top, right, bottom, left.
padding: 20px;
2 values
Use 2 values to apply the first oneBottom and top,the secondabout.
padding: 20px 10px;
3 values
Use 3 values to apply the first oneoptimal,the secondabout,The thirdbottom.
padding: 20px 10px 30px;
4 values
Use 4 values to apply the first oneoptimal,the secondcorrect,The thirdbottom,the fourthLeft.
padding: 20px 10px 5px 0px;
So, the order isTop right-bottom left.
Accepted value
padding
Accept the value expressed in any length unit, the most common are px, em, rem, butThere are many others.
Download mine for freeCSS Manual
More CSS tutorials:
- Flexbox guide
- CSS grid tutorial
- CSS variables (custom attributes)
- Introduction to PostCSS
- CSS guarantees metallicity
- How to center an element using CSS
- CSS system fonts
- How to print HTML with styles
- Getting started with CSS transition
- CSS animation tutorial
- Introduction to CSS
- CSS guide
- How to set up Tailwind with PurgeCSS and PostCSS
- Tail wind cheat sheet
- How to continuously rotate an image using CSS
- Use CSS to make the table responsive
- How to debug CSS by halving
- CSS selector
- CSS cascade
- CSS specificity
- CSS attribute selector
- CSS colors
- CSS Unit
- CSS url()
- CSS typography
- CSS Box model
- CSS position properties
- CSS media queries and responsive design
- CSS function query
- CSS conversion
- How to style a list with CSS
- CSS vendor prefix
- CSS inheritance
- CSS pseudo-classes
- CSS pseudo elements
- Style HTML tables with CSS
- CSS Display property
- CSS calc() function
- CSS border
- Use @import to import CSS files
- CSS error handling
- CSS filter
- CSS Box size
- CSS background
- CSS comments
- CSS fonts
- CSS padding
- CSS float property and clear
- CSS normalization
- CSS z-index property
- How to disable text selection using CSS
- How to use CSS to place items at the bottom of their container
- How to invert colors using CSS
- Responsive front tags in CSS
- Responsive YouTube video embedding
- What is a good CSS breakpoint value for responsive design?
- How to align the center in Flexbox