Blogger Information
Blog 5
fans 0
comment 0
visits 3905
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第五课使用使用相对定位做一个十字架
小孔的博客
Original
830 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>盒子模型-相对定位</title>
    <style>
        /*1. 子元素是单行行内元素: 如a, span <br>*/
        /*a:水平居中: 在父元素应用: text-align: center;*/
        /*b:垂直居中: 在行内子元素上设置行高与父元素等高: line-height:200px;*/

        .box1 a,.box2 a,.box3 a,.box4 a{
            line-height: 302px; /*群定义所有box里面的a*/

        }
        .box1 {
            width: 300px;/*宽*/
            height: 300px;/*高*/
            padding: 1px;/*所有外边距*/
            border:1px solid;/*外边框大小*/
            border-color: #010006;/*外边框颜色*/
            background-color: lightgreen;/*背景*/
            text-align: center;/*水平居中*/
            position: relative;
            left: 303px;
            top: 0;
        }
        .box2 {
            width: 300px;/*宽*/
            height: 300px;/*高*/
            padding: 1px;/*所有外边距*/
            border:1px solid;/*外边框大小*/
            border-color: #fe190e;/*外边框颜色*/
            background-color: #ee8fca;
            text-align: center;
            position: relative;
            left: 0px;
            top: 0px;
        }
        .box3 {
            width: 300px;/*宽*/
            height: 300px;/*高*/
            padding: 1px;/*所有外边距*/
            border:1px solid;/*外边框大小*/
            border-color: #191cfb;/*外边框颜色*/
            background-color: #c5ee46;
            text-align: center;
            position: relative;
            left: 606px;
            top:-304px;
        }
        .box4 {
            width: 300px;/*宽*/
            height: 300px;/*高*/
            padding: 1px;/*所有外边距*/
            border:1px solid;/*外边框大小*/
            border-clor: #fb357a;/*外边框颜色*/
            background-color: #15e9ee;
            text-align: center;
            position: relative;
            left: 303px;
            top:-304px;
        }

    </style>
</head>
<body>
<div class="box1">
    <a>php中文网</a>
</div>
<div class="box2">
    <a>php中文网</a>
</div>
<div class="box3">
    <a>php中文网</a>
</div>
<div class="box4">
    <a>php中文网</a>
</div>
</body>
</html>

运行实例 »

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

学习了 相对定位使用盒子模型进行定位设置

position: relative; 定位
text-align: center; 文本居中

border:1px solid;/*外边框大小*/

border-color: #fe190e;/*外边框颜色*/


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