Javascript examples for CSS Style Property:width
The width property sets or gets the width an element.
Value | Description |
---|---|
auto | The browser calculates the width. This is default |
length | Defines the width in length units |
% | Defines the width in percentage of the parent element |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
Item | Value |
---|---|
Default Value: | auto |
Return Value: | A String, representing the width of an element |
CSS Version | CSS1 |
Set the width of a <button> element:
<!DOCTYPE html> <html> <body> <img id="myImg" src="http://java2s.com/resources/c.png" style="width:100px;height:132px;"> <br> <button type="button" onclick="myFunction()">Return width of image</button> <script> function myFunction() {//from www .ja v a2 s . com document.getElementById("myImg").style.width = '200px'; } </script> </body> </html>