Blogger Information
Blog 41
fans 2
comment 1
visits 26196
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
3.23作业
郭恒的博客
Original
484 people have browsed it

QQ图片20180325163004.jpgQQ图片20180325163018.jpg

实例 3.23

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3.23css控制元素对齐技巧</title>
    <style>
        .box1{
            width: 200px;
            height: 200px;
            background-color: yellow;
            text-align: center;
        }
        .box1 a{
            line-height: 200px;
        }
        .box2{
            width: 200px;
            height: 200px;
            background-color: green;
            text-align: center;
            /*以下声明可以使多个行内元素在块级元素中垂直居中*/
            display: table-cell;/*将当前块显示方式改为表格单元格方式*/
            vertical-align: middle;/*设置单元格内元素垂直居中*/
        }
        .box3{
            width: 200px;
            height: 200px;
            background-color: blue;
            display: table-cell;/*将当前块显示方式改为表格单元格方式*/
            vertical-align: middle;/*设置单元格内元素垂直居中*/
        }
        .box3 .ch{
            width: 100px;
            height: 100px;
            background-color: red;
            margin: auto; /*auto用于浏览器自动计算*/
        }
        .box4{
            width: 200px;
            height: 200px;
            background-color: fuchsia;
            text-align: center;
            display: table-cell;/*将当前块显示方式改为表格单元格方式*/
            vertical-align: bottom;/*设置单元格内元素垂直居中*/
        }
        .box4 ul{
            margin: 0;
            padding: 0;
            /*line-height: 200px;*/
        }
        .box4 li{
            list-style: none;
            display: inline;
        }
    </style>
</head>
<body>
      <!--父元素一定是个块级元素,根据元素的不同,有几种对齐方式-->
      <!--1.子元素是行内元素:如a,span-->
        <!--a.水平居中:在父元素上面设置: text-align:center;-->
        <!--b.垂直居中:在行内元素设置行高与父元素对齐;line-height-->
       <div class="box1">
           <a href="">你好</a>
       </div>
      <hr>
        <!--子元素为多行文本-->
           <!--a 水平居中: 在父元素中设置:text-align:center;-->
           <!--b 垂直居中:在父元素中设置display:table-cell;vertical-align:middle;-->
        <div class="box2">
            <a href="">你好</a><br>
            <span>hhh</span>
        </div>
      <hr>
            <!--子元素是块级元素-->
              <!--a 水平居中:子元素上设置左右自动 margin:auto;-->
              <!--b 垂直居中:在父元素中设置display:table-cell;vertical-align:middle;-->
      <div class="box3">
          <div class="ch">hshs</div>
      </div>
      <hr>
              <!--子元素是不定宽的块元素-->
              <!--a 水平居中:在父元素中设置:text-align:center;-->
              <!--b 垂直居中:给分页的ul,加行高等于父元素-->
              <!--c 底边居中:与多行文本垂直居中处理一样-->
      <div class="box4">
          <ul >
              <li><a href="">1</a></li>
              <li><a href="">2</a></li>
          </ul>
      </div>
</body>
</html>

运行实例 »

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


Correction status:qualified

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
  • 2018-03-16 15:12:44