Blogger Information
Blog 60
fans 0
comment 1
visits 37595
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3月23日作业
威灵仙的博客
Original
452 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS控制元素对齐</title>
    <style type="text/css">
    /*单行文本在块元素中的左右,垂直居中对齐*/
        .box1 {
            width:200px;
            height:200px;
            text-align:center; /*可以使内部多行行内元素水平居中*/
            background-color:yellow;
            line-height:200px;/*子元素设置行高与父元素高度相同*/
        }

        /*多行文本在父元素是块元素情况下的上下,垂直对齐方式*/
        .box2 {
            width:200px;
            height:200px;
            background-color:red;
            text-align:center; /*可以使内部多行行内元素水平居中*/
            display: table-cell;  /*设置显示方式为表格单元格*/
            vertical-align: middle; /*设置该单元格内的元素垂直居中*/

        }
        /*子元素是块元素,父元素也块元素,如何左右,上下居中,左右使用margin:auto,上下使用display:table-cell,vartical-align:middle;*/

        .box3 {
            width:200px;
            height:200px;
            background-color:green;
            display: table-cell;
            vertical-align:middle;
        }

        .box3 .child {
            width: 100px;
            height: 100px;
            background-color: #F4FF0A;
            margin: auto;  /*水平居中*/
        }
/*  子元素是不定宽的块元素:最常见的分页导航 */
        .box4 {
            width:200px;
            height:200px;
            background-color:pink;
            text-align:center;
            display:table-cell;
            vertical-align: bottom;

        }
        .box4 ul {
            margin:0;
            padding:0;
        }

        .box4 li {
            list-style: none;
            display:inline;
        }


    </style>
</head>
<body>
    <div class="box1">
        <a href="">PHP学习网站</a>

    </div>
    <hr><br>

    <div class="box2">
        <span>PHP中文网</span><br>
        <span>www.php.cn</span>
    </div>
    <hr><br>


    <div class="box3">
        <div class="child"></div>
    </div>
    <hr><br>

    <div class="box4">
        <ul class="child1">
            <li><a href="">1</a></li>
            <li><a href="">2</a></li>
            <li><a href="">3</a></li>
            <li><a href="">4</a></li>
            <li><a href="">5</a></li>
        </ul>
    </div>

</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1282466011.jpg

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post