Home >Web Front-end >HTML Tutorial >HTML---CSS cascading style sheet

HTML---CSS cascading style sheet

不言
不言Original
2018-04-26 14:34:482362browse

This article shares with you the content of HTML---CSS Cascading Style Sheet. Friends in need can refer to it


CSS Cascading Style Sheet


1. Separation of structure, style, and behavior

<!--样式-->
<style type="text/css">
    p{
        background-color:green;
        height:100px;
        width:400px;
        border:1px solid red;
    }
    h2{
        background-color:#aaa;
        height:100px;
        width:400px;
        border:1px solid red;
    }
    <!--选择器-->
    .yellow{
        background-color:yellow;
        height:300px;
        width:600px;
        border:1px solid red;
    }
</style>

<!--行为-->
<script type="text/javascript">
    <!--当页面加载完毕,我们就执行一个函数,来完成对h2的操作-->
    window.onload()=function(){
        <!--获取要操作的h2标签-->
        h2Node=document.getElementById("tt");
        <!--当鼠标经过,我们就改变h2的外观-->
        h2Node.onmouseover=function(){
            this.className="yellow";
        }
        <!--鼠标离开,就恢复h2的外观和大小-->
        h2Node.onmouseout=function(){
            this.className="";
        }
    }

</script>
<body>
    <h2 id="tt">静夜思</h2>
    <p>床前明月光</p>
</body>

2. Classification of css
( 1) id selector
(2) Tag selector
(3) Class selector
(4) Group selector
(5) Wildcard selector
(6) Pseudo class selection Selector (operation on hyperlinks)
(7) Derived selector, also called compound selector
Priority of selector: proximity principle, the smaller the range, the higher the priority
You can use !important Change priority

<style>
    /*id选择器*/
    #a01{
        color:red;
    }
    /*标签选择器*/
    p{
        color:blue;
    }
    /*类选择器*/
    .c01{
        background:green;
    }
    /*分组选择器*/
    h1,h2,h3{
        color:yellow
    }
    /*通配符选择器*/
    *{
        background:#aaa
    }
    /*派生选择器*/
    li strong{
        color:orange;
    }
</style>
<body>
    <ul>
        <li><strong>无序列表选项1</strong></li>
        <li>无序列表选项2</li>
        <li>无序列表选项3</li>
        <li>无序列表选项4</li>
    </ul>
    <h1 id="a01">静夜思</h1>
    <h2 class="c01">床前明月光</h2>
    <h3>疑是地上霜</h3>
    <p>举头望明月</p>
    <strong>低头思故乡</strong>
</body>

Pseudo-class selector
In browsers that support CSS, different states of links can be displayed in different ways. These states include: active state, has been Visited state, unvisited state, and mouseover state
The order of pseudo-classes: link, visited,hover,active

<style type="text/css">
    a:link{ /*未被访问状态*/
        color:#000000;
        text-decoration:none;
    }
    a:visited{ /*已访问过的*/
        color:#FF6633;
    }
    a:hover{ /*鼠标悬停*/
        color:#00FF66;
        rext-decoration:underline;
    }
    a:active{
        color:#CCFF6;
    }
</style>
<body>
    <a href="#">构造css规则</a>
</body>

focus pseudo-class
Get in the element Add special styles to elements when focused

c9ccee2e6ea535a969eb3f532ad9fe89
    input:focus{
        background-color:#FF0066
    }
531ac245ce3e4fe3d50054a55f265927
6c04bd5ca3fcae76e30b72ad730ca86d
    e388a4556c0f65e1904146cc1a846bee
        e7f5741c8aebd1cf4935f2b73c310eb7
    94b3e26ee717c64999d7867364b1b4a3
36cc49f0c466276486e50c850b7e4956

3. How to use css
(1) Inline

<style>
    li{
        color:red
    }
</style>
<body>
    <ul>
        <li><strong>无序列表选项1</strong></li>
        <li>无序列表选项2</li>
        <li>无序列表选项3</li>
        <li>无序列表选项4</li>
    </ul>

</body>

(2) Inline

6c04bd5ca3fcae76e30b72ad730ca86d
    e388a4556c0f65e1904146cc1a846beefeb9eb9529a5c82c05b1eb381b6d651d我45a2772a6b6107b401db3c9b82c049c2能抽象出整个世界94b3e26ee717c64999d7867364b1b4a3
36cc49f0c466276486e50c850b7e4956

(3)Import type

<style type="text/css">
    @import "文件路径";
</style>
<body>
    <ul>
        <li><strong>无序列表选项1</strong></li>
        <li>无序列表选项2</li>
        <li>无序列表选项3</li>
        <li>无序列表选项4</li>
    </ul>
    <h1 id="a01">静夜思</h1>
    <h2 class="c01">床前明月光</h2>
    <h3>疑是地上霜</h3>
    <p>举头望明月</p>
    <strong>低头思故乡</strong>
</body>

Create .css file

    #a01{
        color:red;
    }
    p{
        color:blue;
    }

(4) Link type

<link href="文件路径" rel="stylesheet" type="text/css">
<body>
    <ul>
        <li><strong>无序列表选项1</strong></li>
        <li>无序列表选项2</li>
        <li>无序列表选项3</li>
        <li>无序列表选项4</li>
    </ul>
    <h1 id="a01">静夜思</h1>
    <h2 class="c01">床前明月光</h2>
    <h3>疑是地上霜</h3>
    <p>举头望明月</p>
    <strong>低头思故乡</strong>
</body>

Create .css file

    #a01{
        color:red;
    }
    p{
        color:blue;
    }

Related recommendations:

Detailed description of CSS Cascading Style Sheet

##CSS Cascading Style Sheet_html/css_WEB-ITnose

The above is the detailed content of HTML---CSS cascading style sheet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn