HTML DOM शैली की चौड़ाई गुण HTML दस्तावेज़ में किसी तत्व की चौड़ाई CSS गुण लौटाता है और संशोधित करता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
-
वापसी की चौड़ाई
object.style.width
-
चौड़ाई संशोधित करना
object.style.width = “value”
उदाहरण
आइए शैली चौड़ाई गुण का एक उदाहरण देखें -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
p {
border: 2px solid #fff;
margin: 1.5rem auto;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style width Property Example</h1>
<p>
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
This is paragraph 1 with some dummy text.
</p>
<button onclick="add()" class="btn">Change Width</button>
<script>
function add() {
document.querySelector('p').style.width = "50%";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -

"चौड़ाई बदलें . पर क्लिक करें अनुच्छेद तत्व की चौड़ाई बदलने के लिए बटन -
