css height attribute definition and usage
In css, the height attribute is used to set the height of an element, excluding padding and borders. Or page margins, which can add padding, borders, and margins outside the content area. Inline non-replaced elements ignore this attribute.
The height attribute is used a lot and is a commonly used attribute in CSS. When you need to set the height of an element, you can use this attribute to achieve it. If you need to set the width of an element, we can use the width attribute to do so. The height attribute and the width attribute are often used together to control the size of an element.
css height attribute syntax format
css syntax: height:auto/length/%/inherit;
JavaScript syntax: object.style.height ="50px";
css height attribute value description
auto: default value, the browser will calculate the actual height;
length: use Units such as px and cm define the height;
%: based on the percentage height of the block-level object that contains it;
inherit: specifies that the value of the height attribute should be inherited from the parent element
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>css height属性设置元素的高度</title> <style type="text/css"> div{width: 400px;border:1px solid red;} #div1{height: 50px;} #div2{height: 80px;} #div3{height: 100px;} </style> </head> <body> <div id="div1">div1</div> <div id="div2">div2</div> <div id="div3">div3</div> </body> </html>
Running result
The above is the detailed content of How to use css height attribute. For more information, please follow other related articles on the PHP Chinese website!