line-height 属性介绍

 

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}pre{margin:0cm;margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:12.0pt;font-family:宋体;mso-bidi-font-family:宋体;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:595.3pt 841.9pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:42.55pt;mso-footer-margin:49.6pt;mso-paper-source:0;layout-grid:15.6pt;}div.Section1{page:Section1;}-->

line-height属性介绍

CSS2.0 手册中对该属性的介绍如下:

语法:

line-height : normal | length

取值

normal : 默认值。默认行高

length : 百分比数字 | 由浮点数字和单位标识符组成的长度值,允许为负值。其百分比取值是基于字体的高度尺寸。请参阅 长度单位 

 

说明

检索或设置对象的行高。即字体最底端与字体内部顶端之间的距离。

行高是字体下延与字体内部高度的顶端之间的距离。为负值的行高可用来实现阴影效果。

假如一个格式化的行包括不止一个对象,则最大行高会被应用。在这种情况下,此属性不可以为负值。

此属性对于currentStyle 对象而言是只读的。对于其他对象而言是可读写的。

对应的脚本特性为lineHeight

 

典型应用:line-height 使文本垂直居中

当指定line-height:100px 时,文本将默认以行高100px 的高度在垂直方向进行居中。

注意,用line-height
只对文字起作用,对于图片时失效。

 

line-height height 的影响

当元素设置了 line-height height 值后,其影响因为有浏览的差异而不同。

示例:

css:

       .div1{

              height:50px;

              line-height:100px;

              background-color:red;

       }

       .div2{

              background-color:green;

              height:20px;

       }

html:

       <div class="div1">

              文本垂直居中

       </div>

       <divclass="div2"></div>

效果如下:

上图为Firefox 下的结果,从上图我们可以看出文本的垂直居中只和 line-height 的值有关系,根据 line-height 值大小垂直居中,line-height 值的设置不会改变元素的高度。

 

 

上图为 IE 下的结果,我们可以看出在 IE 浏览器下 line-height 值的大小对元素的高度会有影响。在本示例中我们指定 div1 的高度为 50 px,但是由于我们同时指定了 line-height 高度为 100px,结果 div1 的实际占用空间高度为 100 px

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值