博客列表 >元素对齐与盒子定位--2018-08-17 12:00

元素对齐与盒子定位--2018-08-17 12:00

Aken的博客
Aken的博客原创
2018年08月17日 11:26:54737浏览

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定位实现十字架</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        .z{
            position: relative;
        }
        .div1{
            width: 100px;
            height: 100px;
            background:lightskyblue;
            position: absolute;
            left: 100px;
            top: 0px;
        }
        .div2{
            width: 100px;
            height: 100px;
            background:lightblue;
            position: absolute;
            top: 100px;
            left: 0px;
        }
        .div3{
            width: 100px;
            height: 100px;
            background:lightcoral;
            position: absolute;
            left: 200px;
            top: 100px;
        }
        .div4{
            width: 100px;
            height: 100px;
            background: lightcyan;
            position: absolute;
            top: 200px;
            left: 100px;
        }
    </style>
</head>
<body>
<div class="z">
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="div3"></div>
    <div class="div4"></div>
</div>

</body>
</html>

运行实例 »

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

QQ图片20180817112530.png


实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素对齐方式</title>
    <style>
        .div1{
            width: 100px;
            height: 100px;
            background: lightblue;
            line-height: 100px;
            text-align: center;
        }
        .div2{
            width: 150px;
            height: 150px;
            background: lightcyan;
            text-align: center;
        }
        .div2 p{
            margin: 0;
            line-height: 150px;
        }
        .div3{
            width: 200px;
            height: 200px;
            background: lightseagreen;
            text-align: center;
            display: table-cell;
            vertical-align: middle;
        }
        .div4{
            width: 200px;
            height: 200px;
            background: lightpink;
            text-align: center;
            display: table-cell;
            vertical-align: middle;
        }
        .div4 p{
            margin: 0;
        }
    </style>
</head>
<body>

<div class="div1">div1内容</div>
<div class="div2"><p>div2内容</p></div>
<div class="div3"><a href="#">aaa</a><span>spanspan</span></div>
<div class="div4"><p>p</p></div>

</body>
</html>

运行实例 »

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


QQ图片20180817112639.png

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议