Element HTML DOM clientWidth
❮ Objekt prvkuPříklad
Získejte výšku a šířku „myDIV“ včetně odsazení:
const elmnt = document.getElementById("myDIV");
let text = "Height with padding: " + elmnt.clientHeight + "px<br>";
text += "Width with padding: " + elmnt.clientWidth + "px";
Další příklady níže.
Definice a použití
Vlastnost clientWidth
vrací viditelnou šířku prvku v pixelech, včetně odsazení, ale ne ohraničení, posuvník nebo okraj.
Vlastnost clientWidth
je pouze pro čtení.
Tutorial:
Viz také:
Vlastnost Element clientHeight
Vlastnost Element offsetHeight
Chcete-li k prvku přidat posuvníky, použijte vlastnost CSS overflow .
Syntax
element.clientWidth
Návratová hodnota
Typ | Popis |
Číslo | Viditelná šířka prvku (v pixelech) včetně odsazení. |
Rozdíl mezi clientHeight/clientWidth a offsetHeight/offsetWidth
Bez posuvníku:
const elmnt = document.getElementById("myDIV");
let text = "";
text += "Height with padding: " + elmnt.clientHeight + "px<br>";
text += "Height with padding and border: " + elmnt.offsetHeight + "px<br>";
text += "Width with padding: " + elmnt.clientWidth + "px<br>";
text += "Width with padding and border: " + elmnt.offsetWidth + "px";
S posuvníkem:
const elmnt = document.getElementById("myDIV");
let text = "";
text += "Height with padding: " + elmnt.clientHeight + "px<br>";
text += "Height with padding, border and scrollbar: " + elmnt.offsetHeight + "px<br>";
text += "Width with padding: " + elmnt.clientWidth + "px<br>";
text += "Width with padding, border and scrollbar: " + elmnt.offsetWidth + "px";
Podpora prohlížeče
element.clientWidth
je podporován ve všech prohlížečích:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
❮ Objekt prvku