欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
    CSS中通过属性vertical-align来设置段落的垂直对齐方式。
    注意,对于文字本身而言,该属性对于块级元素并不起作用,例如<p>和<div>等标记,但是,对于表格而言,这个属性十分的重要。
    <spanstyle="font-size:24px;"><html>
    <head>
    <title>
    垂直对齐
    </title>
    <style>
    <!--
    td.top{vertical-align:top;}
    td.bottom{vertical-align:bottom;}
    td.middle{vertical-align:middle;}
    -->
    </style>
    </head>
    <body>
    <tablecellpadding="2"cellspacing="0"border="1">
    <tr>
    <td><imgsrc="http://scs.ganjistatic1.com/gjfs12/M09/A3/B3/CgEHC1VGJz2HZm6eAAEe8iEJ1Go460_600-0_6-0.jpg"border="0"></td>
    <tdclass="top">垂直对齐方式,top</td>
    </tr>
    <tr>
    <td><imgsrc="http://scs.ganjistatic1.com/gjfs12/M09/A3/B3/CgEHC1VGJz2HZm6eAAEe8iEJ1Go460_600-0_6-0.jpg"border="0"></td>
    <tdclass="bottom">垂直对齐方式,bottom</td>
    </tr>
    <tr>
    <td><imgsrc="http://scs.ganjistatic1.com/gjfs12/M09/A3/B3/CgEHC1VGJz2HZm6eAAEe8iEJ1Go460_600-0_6-0.jpg"border="0"></td>
    <tdclass="middle">垂直对齐方式,middle</td>
    </tr>
    </body>
    </html>
    </span>
    如上代码,建立了一个3行2列的表格,其中左侧一列均为图片,起到了将单元格的高度加大的作用,同时也作为对比。
    右侧的一列为文字,分别采用了顶端对齐、底端对齐和中间对齐的方式,对应的CSS的值分别为top、bottom和middle。
    如果,对vertical-align属性设置了具体的数值,对于文字本身,则可以在垂直方向上发生位移。
    <spanstyle="font-size:24px;"><html>
    <head>
    <title>
    垂直对齐
    </title>
    <style>
    <!--
    span.zs{vertical-align:10px;}
    span.fs{vertical-align:-10px;}
    -->
    </style>
    </head>
    <body>
    <p>给对齐属性设置具体<spanclass="zs">数值</span>,正数</p>
    <p>给对齐属性设置<spanclass="fs">具体</span>数值,负数</p>
    </body>
    </html>
    </span>
    如上代码,当属性值为正数时,文字将向上移动相应的数值,设置为负数时则向下移动。
    此外,vertical属性还有很多其他值,不过主要是适用于图片。






本文转载自中文网


 

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/rumen/r57234.shtml