Αξία padding του Style

Ορισμός και χρήση

padding Η ιδιότητα ρυθμίζει ή επιστρέφει την εσωτερική απόσταση του στοιχείου.

Αυτή η ιδιότητα μπορεί να αποδεχτεί μια έως και τέσσερις τιμές:

π الخاصτη και padding attribute καθιστούν χώρο γύρω από το στοιχείο. Ωστόσο, η διαφορά βρίσκεται στο ότι το margin εισάγει χώρο γύρω από το περίγραμμα, ενώ το padding εισάγει χώρο μέσα στο περίγραμμα του στοιχείου.

  • μια τιμή, π.χ.: div {padding: 50px} - τα τέσσερα άκρα θα έχουν εσωτερικό περιθώριο 50px
  • Δύο τιμές, π.χ.: div {padding: 50px 10px} - τα πάνω και κάτω εσωτερικά περιθώρια θα είναι 50px, τα αριστερά και δεξιά εσωτερικά περιθώρια θα είναι 10px
  • Three values, for example: div {padding: 50px 10px 20px} - the top inner padding is 50px, the left and right inner padding is 10px, and the bottom inner padding is 20px
  • Four values, for example: div {padding: 50px 10px 20px 30px} - the top inner padding is 50px, the right inner padding is 10px, the bottom inner padding is 20px, and the left inner padding is 30px

See also:

CSS Tutorial:Περιθώρια CSS

CSS Reference Manual:padding attribute

Example

Example 1

Set the inner padding of the <div> element:

document.getElementById("myDiv").style.padding = "50px 10px 20px 30px";

Try it yourself

Example 2

Change the inner padding of all four sides of the <div> element to "25px":

document.getElementById("myDiv").style.padding = "25px";

Try it yourself

Example 3

Returns the inner padding of the <div> element:

alert(document.getElementById("myDiv").style.padding);

Try it yourself

Example 4

Difference between margin and padding properties:

function changeMargin() {
  document.getElementById("myDiv").style.margin = "100px";
}
function changePadding() {
  document.getElementById("myDiv2").style.padding = "100px";
}

Try it yourself

Syntax

Return padding attribute:

object.style.padding

Set padding attribute:

object.style.padding = "%|length|initial|inherit"

Attribute value

Value Description
% Define inner padding as a percentage of the parent element's width.
length Define inner padding with length units.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical details

Default value: 0
Return value: A string representing the element's inner padding.
CSS version: CSS1

browser supports

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη