CSS3偽類和錨點(diǎn)

2017-05-03_152524.jpg
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>CSS3偽類和偽元素</title>
</head>
<style>
    *{margin:0px;padding:0px;}
    a{font-size:18px;}
    div{width:100px;height:100px;background: red;display: none;}
    div:target{display: block;}/*代表的就是最終目的*/
    input[type=button]:disabled{color:red;} /*找到disabled*/
    input[type=checkbox]:checked{width:50px;height:50px;} /*找到checkbox*/
    h2~h1{color:gold;}/*第一個(gè)h1沒有變化。而是h2后面的節(jié)點(diǎn)發(fā)生了變化*/
    label{overflow:hidden;position:relative;}
    input[type=radio]{position:absolute;left:-100px;top:-100px;}
    span{width:50px;height:50px;border:5px solid #ccc;display: block;}
    input[type=radio]:checked~span{background: gold;}
</style>
<body>
<p>主要是就是測(cè)試CSS3里面的偽類target</p>
<a href="#div1">a1</a>
<a href="#div2">a2</a>
<a href="#div3">a3</a>
<div id="div1">第一個(gè)</div>
<div id="div2">第二個(gè)</div>
<div id="div3">第三個(gè)</div>
<input type="button"value="點(diǎn)擊" disabled>
<input type="checkbox">籃球
<h1>第一名</h1>
<h2>第二名</h2>
<h1>第一名</h1>
模擬單選框
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
</body>
</html>

自定義單選框

自定義單選框.gif
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>CSS3偽類和偽元素</title>
</head>
<style>
    *{margin:0px;padding:0px;}
    label{overflow:hidden;position:relative;display:block;}  /*超出后隱藏。定位相對(duì)*/
    input[type=radio]{position:absolute;left:-100px;top:-100px;}  /*input絕對(duì)定位*/
    span{width:50px;height:50px;border:5px solid #ccc;display: block;}/*要替換的*/
    input[type=radio]:checked~span{background: gold;}/*選中后要替換的*/
</style>
<body>
模擬單選框
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
<label>
    <input type="radio"name="r1">
    <span></span>
</label>
</body>
</html>

這里要特別注意:first-letter,first-line,在CSS里面查找的越準(zhǔn)確,級(jí)別優(yōu)先度最高而不是看!important

222.png

文本偽類

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <title>CSS3偽類和偽元素</title>
</head>
<style>
    *{margin:0px;padding:0px;}
     #p1{width: 300px; border: 1px solid #000; font: 12px/30px "微軟雅黑"; padding: 10px;}
     #p1:first-line{color:blue;font-size:12px;}
     #p1:first-letter{font-size:24px;color:red;}
     #p1::selection{color:gold;}
     #p1:before{content:"帥哥";font-size:24px;color:gold;}/*這樣他是不會(huì)改變樣式的,只是加了帥哥*/
     #p1:after{content:"美女";font-size:24px;color:gold;} /*這樣他就會(huì)發(fā)生變化了。因?yàn)闆]有first-letter*/
</style>
<body>
<p id="p1">
    前端開發(fā)的世界從未有過無聲的寂靜,精彩紛呈的互聯(lián)網(wǎng)也不曾出現(xiàn)片刻安寧,在HTML5&CSS3被炒至沸沸揚(yáng)揚(yáng)的今天,全面系統(tǒng)地掌握此項(xiàng)技能,是加重技術(shù)含金量的重要砝碼!現(xiàn)已為你開啟一個(gè)嶄新的職業(yè)規(guī)劃……
</p>
</body>
</html>

對(duì)應(yīng)的效果圖

2017-05-04_105011.jpg

排除元素

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        h1:not(.h2) {background: red;} /*也就是除了class是h2的以外都變成紅色*/
    </style>
</head>
<body>
    <h1>h1</h1>
    <h1 class="h2">h1</h1>
    <h1>h1</h1>
</body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文轉(zhuǎn)載自:眾成翻譯譯者:為之漫筆鏈接:http://www.zcfy.cc/article/239原文:http...
    極樂君閱讀 7,545評(píng)論 1 62
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評(píng)論 19 139
  • CSS選擇器結(jié)構(gòu)邏輯圖 接下來按照結(jié)構(gòu)邏輯圖具體講解各個(gè)選擇器的作用及用法; 基本選擇器 基本選擇器主要有以下5類...
    FoolishFlyFox閱讀 658評(píng)論 0 8
  • 1、屬性選擇器:id選擇器 # 通過id 來選擇類名選擇器 . 通過類名來選擇屬性選擇器 ...
    Yuann閱讀 1,752評(píng)論 0 7
  • 一、偽元素和偽類的概念 偽類:首先是類的一種,類似class,代表一些元素的狀態(tài),邏輯上存在,文檔樹中卻無須標(biāo)識(shí)的...
    07120665a058閱讀 1,549評(píng)論 0 4

友情鏈接更多精彩內(nèi)容