Stil marginBottom- Eigenschaft
Beispiel
Legen Sie den unteren Rand eines <div>-Elements fest:
document.getElementById("myDiv").style.marginBottom = "50px";
Definition und Verwendung
Die Eigenschaft marginBottom legt den unteren Rand eines Elements fest oder gibt ihn zurück.
Sowohl die Eigenschaft margin als auch die Eigenschaft padding fügen Leerzeichen um ein Element ein. Der Unterschied besteht jedoch darin, dass margin den Abstand um den Rand einfügt, während padding den Abstand innerhalb des Rands eines Elements einfügt.
Browser-Unterstützung
Property | |||||
---|---|---|---|---|---|
marginBottom | Yes | Yes | Yes | Yes | Yes |
Syntax
Geben Sie die Eigenschaft marginBottom zurück:
object.style.marginBottom
Legen Sie die Eigenschaft marginBottom fest:
object.style.marginBottom = "%|length|auto|initial|inherit"
Eigenschaftswerte
Value | Description |
---|---|
% | Defines the bottom margin in % of the width of the parent element |
length | Defines the bottom margin in length units |
auto | The browser sets the bottom margin |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technische Details
Standardwert: | 0 |
---|---|
Rückgabewert: | Ein String, der den unteren Rand eines Elements darstellt |
CSS-Version | CSS1 |
Mehr Beispiele
Beispiel
Ändere den unteren Rand eines <div>-Elements wieder auf „normal“:
document.getElementById("myDiv").style.marginBottom = "0px";
Beispiel
Gibt den unteren Rand eines <div>-Elements zurück:
alert(document.getElementById("myDiv").style.marginBottom);
Beispiel
Unterschied zwischen marginBottom und paddingBottom:
function changeMargin() {
document.getElementById("myDiv").style.marginBottom = "100px";
}
function changePadding() {
document.getElementById("myDiv2").style.paddingBottom = "100px";
}
Verwandte Seiten
CSS-Tutorial: CSS-Rand
CSS-Referenz: margin-bottom-Eigenschaft
HTML-DOM-Referenz: Margin-Eigenschaft
❮ Style-Objekt