Blogger Information
Blog 4
fans 0
comment 1
visits 2892
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
演示css中的选择器优先级以及盒模型的简单案例
茉堇的博客
Original
846 people have browsed it

CSS选择器:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>常用选择器优先级</title>
    <style>
       /*标签选择器*/
       h1{
           background-color: #0bcb9a;
       }
        /*类选择器*/
        .bg-blue{
            background-color: red;
        }
        /*id选择器*/
        #by-yellow{
            background-color: #00aba9;
        }
        /*javascript > style > id > class > 标签*/
    </style>
</head>
<body>
<!--元素的通用属性-->
<!--id ***号
    class 性别(类别)
    title 姓名(提示)
    style 个人简介(样式)
    -->
<h1 id="by-yellow" class="bg-blue" title="php.cn" style="color: #bacee4">php中文网</h1>
<script>
    document.getElementById('by-yellow').style.backgroundColor='red';
</script>
</body>
</html>

运行实例 »

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

盒模型padding和margin:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>盒模型</title>
    <link rel="stylesheet" href="static/css/style2.css">
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background-color: #0a8ddf;
            border: 2px solid pink;
            /*内边距 顺序上右下左*/
            padding: 20px;
            /*外边距 顺序上右下左*/
            margin: 0;
        }
        /*.box2是.box1的子元素 width和heigth可以继承 padding和margin 不可以继承*/
        .box2{
            /*继承 inherit */
            width: inherit;
            height: inherit;
            background-color: red;
            border: 2px solid blue;
            /*内边距 顺序上右下左*/
            padding: 20px;
            /*外边距 顺序上右下左*/
            margin: 0;
        }
    </style>
</head>
<body>
<!--盒模型可以设置的6个样式:width、heigth、padding、margin、background-color、border -->
<div class="box1">
    <div class="box2">

    </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