CSS height

CSS height 属性定义与用法

height属性设置元素的高度。

注意: height属性不包括填充,边框,或页边距!

默认值: auto
继承: no
版本: CSS1
JavaScript 语法: object.style.height="50px"

 

CSS height 属性值

描述
auto 默认。浏览器会计算出实际的高度。
length 使用 px、cm 等单位定义高度。
% 基于包含它的块级对象的百分比高度。
inherit 规定应该从父元素继承 height 属性的值。

 

CSS height 浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流浏览器都支持height属性。

注意: IE7和更早的版本不支持"inherit"的值。IE8需要定义!DOCTYPE。IE9支持"inherit"。

 

CSS height 实例

css 设置元素的高度

<!DOCTYPE html>
<html>
<head>
<style>
img.normal
{
height:auto;
}
img.big
{
height:120px;
}
p.ex
{
height:100px;
width:100px;
}
</style>
</head>

<body>
<img class="normal" src="/images/online_demo/logocss.gif" width="95" height="84" /><br>
<img class="big" src="/images/online_demo/logocss.gif" width="95" height="84" />
<p class="ex">The height and width of this paragraph is 100px.</p>
<p>This is some text in a paragraph. This is some text in a paragraph.
This is some text in a paragraph. This is some text in a paragraph.
This is some text in a paragraph. This is some text in a paragraph.</p>
</body>
</html>

在线运行

 

相关文章

CSS 教程: CSS 尺寸

CSS 教程: CSS 盒子模型

CSS 参考手册: width 属性