Blogger Information
Blog 14
fans 0
comment 0
visits 6478
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
各种样式权重的优先级以及盒模型内外边距以及边框。2019年4月25日15时06分
蔡小逗
Original
896 people have browsed it
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>css优先级,以及盒模型</title>
</head>
<style>
 *{
        margin: 0px;
        padding: 0px;
    }
    .box{
        background-color:#00a4b0;
        color:#3d495d;
        width:20%;
        height: 400px;
        float: left;
        line-height:80px;
        font-size:18px;
        text-align: center;

    }
    .box11{
        background-color:#c1ebe6;
        color:#3d495d;
        width:20%;
        height: 400px;
        float: left;
        line-height:80px;
        font-size:18px;
        text-align: center;
    }
    #box{
        background-color:#00a699;
        color: #0e0e0e;
        width: 20%;
        height: 400px;
        float: left;
        line-height:80px;
        font-size:18px;
        text-align: center;
    }
    #box1{
        background-color:#0eb5d6;
        color: #0e0e0e;
        width: 20%;
        height: 400px;
        float: left;
        line-height:80px;
        font-size:18px;
        text-align: center;
    }
    #box2{
        background-color:pink;
        color: #0e0e0e;
        width: 20%;
        height: 400px;
        float: left;
        line-height:80px;
        font-size:18px;
        text-align: center;
    }
    .main2{
        width: 500px;
        height: 200px;
        line-height: 200px;
        font-size: 22px;
        margin:0px auto;
        border: 2px solid #0e0e0e;
        text-align: center;
        padding: 10px;
        background-color: #f0ecf7;
    }
    .main{
        width: 600px;
        height: 300px;
        background-color: #c1ebe6;
        margin: 0px auto;
    }
</style>
<hr>
    <div class="box11">外联样式权重最低</div>
    <div class="box">只有class控制样式时</div>
    <div id="box">只有id控制样式时</div>
    <div class="box" id="box1">当id与class同时控制时,class定义的样式无效,显示id内的样式</div>
    <div class="box" id="box2" style="background-color: lightblue;">当id,class,行内样式同时控制时,class与id定义的样式无效,只显示行内样式</div>
    <hr style="clear: both">
    <br>
    <div class="main">
    <div class="main2">行内样式>id>class>外联样式表</div>
    </div>
</body>
</html>

微信截图_20190425150430.png

微信截图_20190425150448.png

微信截图_20190425150440.png

测试得出,css权重大小,行内样式>id>class>外联样式表

设置内边距会撑开盒模型,使盒模型变大

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