The CSS padding property defines the inner margin of an element. The Padding property accepts length or percent values, but negative values are not allowed.
For example, if you want all H1 elements to have 10-pixel internal margins on each side, this is all you need:
h1 {padding:10px;} You can also set the inner margin of each edge in the order of the top, right, bottom, and left, with different unit or percentage values for each edge:
| The code is as follows |
Copy Code |
H1 {padding:10px 0.25em 2ex 20%;} |
Suppose you now set a padding value that is not the same in FF, IE8, and IE6
The first consideration is the value under FF
| The code is as follows |
Copy Code |
. test{padding:10px}
|
Then consider the value under IE8.
| The code is as follows |
Copy Code |
. test{padding:10px;*padding:9px}
|
Finally consider the value under IE6
| The code is as follows |
Copy Code |
. test{padding:10px;*padding:9px;_padding:8px}
|
That's it.
Do compatibility, first consider FF, opera these browsers, and finally consider IE6.
Take the example, IE8, IE6 can be recognized *, but FF is not recognized.
So take * to do IE8 hack, and _ in FF and IE8 are not recognized, only IE6 can recognize, so with _ do IE6 hack
We talked about padding, but it can still be written like this.
Single-Sided interior margin properties
You can also set up, right, down, and Zonne margins by using the following four separate properties:
| The code is as follows |
Copy Code |
Padding-top Padding-right Padding-bottom Padding-left
|
As you may have thought, the following rule implementation effect is exactly the same as the preceding shorthand rule:
| The code is as follows |
Copy Code |
H1 { padding-top:10px; Padding-right:0.25em; Padding-bottom:2ex; padding-left:20%; } |
Browser support
All browsers support the Padding property.
Note: The property value "Inherit" is not supported for any version of Internet Explorer (including IE8).