Blogger Information
Blog 57
fans 0
comment 0
visits 46848
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
盒子模型+对齐元素+定位
藍錄的博客
Original
771 people have browsed it
  1. 编程实现盒模型的基本要素: 内容,内外边距与边框,并背诵padding与margin的简写规则;


    实例

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>内容外边距内边距</title>
        <!--编程实现盒模型的基本要素: 内容,内外边距与边框,并背诵padding与margin的简写规则;-->
    </head>
    <style>
        .box{
            width: 400px;
            height:400px;
            background-color: lightgreen;
            border:  5px solid #888888;
            padding-top: 15px;
            padding-bottom: 50px;
            padding-left: 2em;
            padding-right: 30px;
        }
        .box2{
            width:200px;
            height:200px;
            background-color: firebrick;
            margin: 18px 32px;
        }
    </style>
    <body>
    <div class="box">
    <div class="box2"></div>
    </div>
    </body>
    </html>

    运行实例 »

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


  2. 编程实现最常用的四种元素对齐方案;

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>元素对齐方式</title>
</head>
<body>

<style>
    /*子元素是单行行内元素*/
    .box1{
        width:200px;
        height:200px;
        background-color: #39FF1B;
        text-align: center;
    }
    .box1 span{
        line-height: 200px;
    }
</style>
<div class="box1">
    <span>PHP天下第一</span>
</div>
<hr>
<!--多行文本居中-->
<style>
    .box2{
        width:200px;
        height:200px;
        background-color: powderblue;
        display: table-cell;
        text-align: center;
        vertical-align: middle;
    }
</style>
<div class="box2">
    <p>PHP天下第一</p>
    <p>PHP宇宙无敌</p>
</div>
<hr>
<style>
    .box3{
        width:200px;
        height:200px;
        background-color: olivedrab;
        display: table-cell;
        vertical-align: middle; /*垂直居中*/



    }
    .box3 .child {
        width:100px;
        height:100px;
        background-color: #FFE80E;
        margin: auto;
    }
</style>

<div class="box3">
    <div class="child"></div>
</div>
<br>
<!--子元素是定宽块元素-->
<style>
    .box4 {
        width: 200px;
        height: 200px;
        background-color: lightblue;
        text-align: center; /*水平居中*/
        display: table-cell;
        vertical-align: bottom; /*位于底部*/
    }
    ul {
        margin: 0;
        padding-left: 0;
    }
    .box4 li {
        display: inline;  /*将块元素转为行内元素*/
    }
</style>
<div class="box4">
    <ul>
        <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>

运行实例 »

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



3.编程实现用五个色块制作一个十字架(相对定位和绝对定位任选一种实现即可)

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用绝对定位做十字架</title>
</head>
<body>
<style>
    .box{
        position: relative;
    }
    .box1{
        width: 200px;
        height: 200px;
        background-color: #FFE80E;
        position: absolute;
        top: 0;
        left: 200px;
    }
    .box2{
        width: 200px;
        height: 200px;
        background-color: lightgreen;
        position: absolute;
        top: 200px;
        left: 0;
    }
    .box3{
        width: 200px;
        height: 200px;
        background-color: rebeccapurple;
        position: absolute;
        top: 400px;
        left: 200px;
    }
    .box4{
        width: 200px;
        height: 200px;
        background-color: pink;
        position: absolute;
        top: 200px;
        left:400px ;
    }
</style>


<div class="box">
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
</div>


</body>
</html>

运行实例 »

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

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