This article shares with you the content of HTML---CSS Cascading Style Sheet. Friends in need can refer to it
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
<style> input:focus{ background-color:#FF0066 } </style> <body> <p> <input type="text" size="20"/> </p> </body>
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
<body> <p><span style="color:blue;font-size:20px">我<span>能抽象出整个世界</p> </body>
(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!