Heim  >  Artikel  >  Web-Frontend  >  HTML---CSS-Cascading-Stylesheet

HTML---CSS-Cascading-Stylesheet

不言
不言Original
2018-04-26 14:34:482277Durchsuche

Dieser Artikel teilt Ihnen den Inhalt über HTML---CSS Cascading Style Sheet. Freunde in Not können sich darauf beziehen


CSS Cascading Style Sheet


1. Trennung von Struktur, Stil und Verhalten

<!--样式-->
<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. Klassifizierung von CSS
( 1) ID-Selektor
(2) Tag-Selektor
(3) Klassen-Selektor
(4) Gruppen-Selektor
(5) Platzhalter-Selektor
(6) Pseudo-Klassen-Selektor (Operation auf Hyperlinks)
(7) Abgeleiteter Selektor, auch zusammengesetzter Selektor genannt
Priorität des Selektors: Proximity-Prinzip, je kleiner der Bereich, desto höher die Priorität
kann verwendet werden !important ändert die Priorität

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

Pseudoklassenselektor
In Browsern, die CSS unterstützen, können verschiedene Zustände des Links auf unterschiedliche Weise angezeigt werden. Zu diesen Zuständen gehören: Aktivitätsstatus, Besucht-Status, Unbesucht-Status und Mouseover-Status
Pseudoklassenreihenfolge: Link, besucht, Hover, aktiv

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

Pseudoklasse fokussieren
Spezielle Stile zu Elementen hinzufügen, wenn sie den Fokus erhalten

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

3. So verwenden Sie 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) Importieren

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

CSS-Datei erstellen

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

(4) Link

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

CSS-Datei erstellen

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

               

Verwandte Empfehlungen:

Detaillierte Beschreibung des CSS Cascading Style Sheets

CSS Cascading Style Sheets_html/css_WEB-ITnose

Das obige ist der detaillierte Inhalt vonHTML---CSS-Cascading-Stylesheet. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn