日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

web前端入门学习 css(8)(新增语义化标签、video/audio、新增input类型、新增表单属性、属性选择器、结构伪类选择器、伪元素选择器、css3盒子模型、模糊、calc函数、过渡

發布時間:2025/3/20 HTML 47 豆豆

https://www.bilibili.com/video/BV1pE411q7FU?p=276

文章目錄

    • html5新特性
      • html5新增語義化標簽 header頭部 nav導航 article內容 section區域 aside側邊欄 footer尾部 標簽
      • 視頻video標簽(支持格式、語法、常見屬性)
      • 音頻audio標簽
      • 多媒體標簽總結
      • html新增input類型
      • html新增表單屬性(輸入是否為空驗證required、輸入提示文本placeholder、自動聚焦輸入框autofocus、輸入框自動記錄歷史輸入autocomplete、多文件上傳mutiple)
    • css3新特性
      • 屬性選擇器 []
      • 結構偽類選擇器 first-child last-child nth-child
        • nth-child和nth-of-type的區別
      • 結構偽類選擇器小結
    • 偽元素選擇器(css替代子盒子直接在父盒子中插入標簽)
      • 偽元素選擇器使用場景1:字體圖標
    • 偽元素選擇器:仿土豆播放效果
    • 雙偽元素清除浮動原理
    • css3盒子模型(以設計盒子長寬顯示盒子,border邊框和padding不會撐大盒子:box-sizing:border-box;)(box-sizing:content-box會撐大盒子)(新style頭)
    • 讓圖片變模糊
    • calc函數(比如使子盒子寬度永遠比父盒子小30px)
    • 過渡transition
    • 進度條案例

html5新特性

html5新增語義化標簽 header頭部 nav導航 article內容 section區域 aside側邊欄 footer尾部 標簽


<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>HTML5新增語義化標簽</title><style>header, nav {height: 120px;background-color: pink;border-radius: 15px;width: 800px;margin: 15px auto;}section {width: 500px;height: 300px;background-color: skyblue;}</style> </head> <body><header>頭部標簽</header><nav>導航欄標簽</nav><section>某個區域</section> </body> </html>

視頻video標簽(支持格式、語法、常見屬性)


<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>video {width: 100%;}</style> </head><body><video src="index_video_bg.mp4" poster='i.jpg' autoplay='autoplay' muted='muted' controls='controls'loop='loop'></video> </body></html>

音頻audio標簽



多媒體標簽總結

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style></style> </head><body><audio src="mzj.mp3" autoplay='autoplay' controls='controls'></audio> </body></html>

html新增input類型

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title> </head><body><!-- 我們驗證的時候必須添加form表單域 --><form action=""><ul><li>郵箱: <input type="email" /></li><li>網址: <input type="url" /></li><li>日期: <input type="date" /></li><li>時間: <input type="time" /></li><li>數量: <input type="number" /></li><li>手機號碼: <input type="tel" /></li><li>搜索: <input type="search" /></li><li>顏色: <input type="color" /></li><!-- 當我們點擊提交按鈕就可以驗證表單了 --><li> <input type="submit" value="提交"></li></ul></form> </body></html>


html新增表單屬性(輸入是否為空驗證required、輸入提示文本placeholder、自動聚焦輸入框autofocus、輸入框自動記錄歷史輸入autocomplete、多文件上傳mutiple)

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>HTML5新增表單屬性</title><style>input::placeholder {color: pink;}</style> </head><body><form action=""><input type="search" name="sear" id="" required="required" placeholder="pink老師" autofocus="autofocus"autocomplete="off"><input type="file" name="" id="" multiple="multiple"><input type="submit" value="提交"></form></body></html>

css3新特性


屬性選擇器 []

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3新增屬性選擇器</title><style>/* 必須是input 但是同時具有 value這個屬性 選擇這個元素 [] *//* input[value] {color:pink;} *//* 只選擇 type =text 文本框的input 選取出來 */input[type=text] {color: pink;}/* 選擇首先是div 然后 具有class屬性 并且屬性值 必須是 icon開頭的這些元素 */div[class^=icon] {color: red;}section[class$=data] {color: blue;}div.icon1 {color: skyblue;}/* 類選擇器和屬性選擇器 偽類選擇器 權重都是 10 */</style> </head><body><!-- 1. 利用屬性選擇器就可以不用借助于類或者id選擇器 --><!-- <input type="text" value="請輸入用戶名"><input type="text"> --><!-- 2. 屬性選擇器還可以選擇屬性=值的某些元素 重點務必掌握的 --><input type="text" name="" id=""><input type="password" name="" id=""><!-- 3. 屬性選擇器可以選擇屬性值開頭的某些元素 --><div class="icon1">小圖標1</div><div class="icon2">小圖標2</div><div class="icon3">小圖標3</div><div class="icon4">小圖標4</div><div>我是打醬油的</div><!-- 4. 屬性選擇器可以選擇屬性值結尾的某些元素 --><section class="icon1-data">我是安其拉</section><section class="icon2-data">我是哥斯拉</section><section class="icon3-ico">哪我是誰</section></body></html>

結構偽類選擇器 first-child last-child nth-child


nth表示第幾個的意思

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3新增結構偽類選擇器</title><style>/* 1. 選擇ul里面的第一個孩子 小li */ul li:first-child {background-color: pink;}/* 2. 選擇ul里面的最后一個孩子 小li */ul li:last-child {background-color: pink;}/* 3. 選擇ul里面的第2個孩子 小li */ul li:nth-child(2) {background-color: skyblue;}ul li:nth-child(6) {background-color: skyblue;}</style> </head><body><ul><li>我是第1個孩子</li><li>我是第2個孩子</li><li>我是第3個孩子</li><li>我是第4個孩子</li><li>我是第5個孩子</li><li>我是第6個孩子</li><li>我是第7個孩子</li><li>我是第8個孩子</li></ul> </body></html>



隔行變色效果,nth-child(even) even表示偶數

可以把5的倍數的盒子選出來設置margin-right:0;

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3新增結構偽類選擇器-nth-child</title><style>/* 1.把所有的偶數 even的孩子選出來 */ul li:nth-child(even) {background-color: #ccc;}/* 2.把所有的奇數 odd的孩子選出來 */ul li:nth-child(odd) {background-color: gray;}/* 3.nth-child(n) 從0開始 每次加1 往后面計算 這里面必須是n 不能是其他的字母 選擇了所有的孩子*//* ol li:nth-child(n) {background-color: pink;} *//* 4.nth-child(2n)母選擇了所有的偶數孩子 等價于 even*//* ol li:nth-child(2n) {background-color: pink;}ol li:nth-child(2n+1) {background-color: skyblue;} *//* ol li:nth-child(n+3) {background-color: pink;} */ol li:nth-child(-n+3) {background-color: pink;}</style> </head><body><ul><li>我是第1個孩子</li><li>我是第2個孩子</li><li>我是第3個孩子</li><li>我是第4個孩子</li><li>我是第5個孩子</li><li>我是第6個孩子</li><li>我是第7個孩子</li><li>我是第8個孩子</li></ul><ol><li>我是第1個孩子</li><li>我是第2個孩子</li><li>我是第3個孩子</li><li>我是第4個孩子</li><li>我是第5個孩子</li><li>我是第6個孩子</li><li>我是第7個孩子</li><li>我是第8個孩子</li></ol> </body></html>

nth-child和nth-of-type的區別

type是給指定類型的子元素排序號;child是給所有子元素排序號

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3新增選擇器nth-type-of</title><style>ul li:first-of-type {background-color: pink;}ul li:last-of-type {background-color: pink;}ul li:nth-of-type(even) {background-color: skyblue;}/* nth-child 會把所有的盒子都排列序號 *//* 執行的時候首先看 :nth-child(1) 之后回去看 前面 div */section div:nth-child(1) {background-color: red;}/* nth-of-type 會把指定元素的盒子排列序號 *//* 執行的時候首先看 div指定的元素 之后回去看 :nth-of-type(1) 第幾個孩子 */section div:nth-of-type(1) {background-color: blue;}</style> </head><body><ul><li>我是第1個孩子</li><li>我是第2個孩子</li><li>我是第3個孩子</li><li>我是第4個孩子</li><li>我是第5個孩子</li><li>我是第6個孩子</li><li>我是第7個孩子</li><li>我是第8個孩子</li></ul><!-- 區別 --><section><p>光頭強</p><div>熊大</div><div>熊二</div></section> </body></html>

結構偽類選擇器小結

偽元素選擇器(css替代子盒子直接在父盒子中插入標簽)

如盒子里的三角標簽



為什么叫“偽元素”?因為元素只在css文件中,在html文件中完全找不到

before和after都是父元素的孩子,但是一個放在盒子前面,一個放在后面,什么意思?(就是字面意思)

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>偽元素選擇器before和after</title><style>div {width: 200px;height: 200px;background-color: pink;}/* div::before 權重是2 */div::before {/* 這個content是必須要寫的 *//* display: inline-block; */content: '我';/* width: 30px;height: 40px;background-color: purple; */}div::after {content: '小豬佩奇';}</style> </head> <body><div></div> </body> </html>

偽元素選擇器使用場景1:字體圖標

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>偽元素選擇器使用場景-字體圖標</title><style>@font-face {font-family: 'icomoon';src: url('fonts/icomoon.eot?1lv3na');src: url('fonts/icomoon.eot?1lv3na#iefix') format('embedded-opentype'),url('fonts/icomoon.ttf?1lv3na') format('truetype'),url('fonts/icomoon.woff?1lv3na') format('woff'),url('fonts/icomoon.svg?1lv3na#icomoon') format('svg');font-weight: normal;font-style: normal;font-display: block;}div {position: relative;width: 200px;height: 35px;border: 1px solid red;}div::after {position: absolute;top: 10px;right: 10px;font-family: 'icomoon';/* content: '?'; */content: '\e91e';color: red;font-size: 18px;}</style> </head><body><div></div> </body></html>


因為沒有下載字體,所以顯示不出來

偽元素選擇器:仿土豆播放效果

為什么要用偽元素,比如播放按鈕,寫在html里,如果有十個播放窗口,就要寫十個盒子,但是如果是寫在css里,只用寫一次就好了

中間千萬別加空格

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>偽元素選擇器使用場景2-仿土豆網顯示隱藏遮罩案例</title><style>.tudou {position: relative;width: 444px;height: 320px;background-color: pink;margin: 30px auto;}.tudou img {width: 100%;height: 100%;}.tudou::before {content: '';/* 隱藏遮罩層 */display: none;position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: rgba(0, 0, 0, .4) url(images/arr.png) no-repeat center;}/* 當我們鼠標經過了 土豆這個盒子,就讓里面before遮罩層顯示出來 */.tudou:hover::before {/* 而是顯示元素 */display: block;}</style> </head><body><div class="tudou"><img src="images/tudou.jpg" alt=""></div><div class="tudou"><img src="images/tudou.jpg" alt=""></div><div class="tudou"><img src="images/tudou.jpg" alt=""></div><div class="tudou"><img src="images/tudou.jpg" alt=""></div> </body></html>


雙偽元素清除浮動原理




css3盒子模型(以設計盒子長寬顯示盒子,border邊框和padding不會撐大盒子:box-sizing:border-box;)(box-sizing:content-box會撐大盒子)(新style頭)

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3盒子模型</title><style>* {margin: 0;padding: 0;box-sizing: border-box;}div {width: 200px;height: 200px;background-color: pink;border: 20px solid red;padding: 15px;box-sizing: content-box;}p {width: 200px;height: 200px;background-color: pink;border: 20px solid red;padding: 15px;/* css3 盒子模型 盒子最終的大小就是 width 200 的大小 */box-sizing: border-box;}</style> </head> <body><div>小豬喬治</div><p>小豬佩奇</p> </body> </html>


以后就使用新style頭:

<style>* {margin: 0;padding: 0;box-sizing: border-box;} </style>

讓圖片變模糊

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>圖片模糊處理filter</title><style>* {margin: 0;padding: 0;box-sizing: border-box;}img {/* blur是一個函數 小括號里面數值越大,圖片越模糊 注意數值要加px單位 */filter: blur(15px);}img:hover {filter: blur(0);}</style> </head><body><img src="../蜥蜴女仆.gif" alt=""> </body></html>


calc函數(比如使子盒子寬度永遠比父盒子小30px)

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3屬性calc函數</title><style>.father {width: 300px;height: 200px;background-color: pink;}.son {/* width: 150px; *//* width: calc(150px + 30px); */width: calc(100% - 30px);height: 30px;background-color: skyblue;}</style> </head> <body><!-- 需求我們的子盒子寬度永遠比父盒子小30像素 --><div class="father"><div class="son"></div></div> </body> </html>

過渡transition


<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3 過渡效果</title><style>div {width: 200px;height: 100px;background-color: pink;/* transition: 變化的屬性 花費時間 運動曲線 何時開始; *//* transition: width .5s ease 0s, height .5s ease 1s; *//* 如果想要寫多個屬性,利用逗號進行分割 *//* transition: width .5s, height .5s; *//* 如果想要多個屬性都變化,屬性寫all就可以了 *//* transition: height .5s ease 1s; *//* 誰做過渡,給誰加 */transition: all 0.5s;}div:hover {width: 400px;height: 200px;background-color: skyblue;}</style> </head> <body><div></div> </body> </html>

進度條案例

<!DOCTYPE html> <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>CSS3過渡練習-進度條</title><style>.bar {width: 150px;height: 15px;border: 1px solid red;border-radius: 7px;padding: 1px;}.bar_in {width: 50%;height: 100%;background-color: red;/* 誰做過渡給誰加 */transition: all .7s;}.bar:hover .bar_in {width: 100%;}</style> </head><body><div class="bar"><div class="bar_in"></div></div> </body></html>

總結

以上是生活随笔為你收集整理的web前端入门学习 css(8)(新增语义化标签、video/audio、新增input类型、新增表单属性、属性选择器、结构伪类选择器、伪元素选择器、css3盒子模型、模糊、calc函数、过渡的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。