Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
大有學(xué)問(wèn)#
#頭條創(chuàng)作挑戰(zhàn)賽#
在HTML基礎(chǔ)上增加了新的標(biāo)簽、新的表單標(biāo)簽、新的表單屬性。
div標(biāo)簽對(duì)搜索引擎來(lái)說(shuō),是沒(méi)有語(yǔ)義的。新增的語(yǔ)義標(biāo)簽主要是針對(duì)搜索引擎識(shí)別的。
頭部標(biāo)簽:<header>
導(dǎo)航標(biāo)簽:<nav>
內(nèi)容標(biāo)簽:<article>
定義文檔某個(gè)區(qū)域:<section>
側(cè)邊欄標(biāo)簽:<aside>
尾部標(biāo)簽:<footer>
代碼練習(xí)
<header>頭部標(biāo)簽</header>
<nav>導(dǎo)航欄標(biāo)簽</nav>
<article class="clearF">
<article class="article1">
內(nèi)容標(biāo)簽
<section>定義文檔某個(gè)區(qū)域</section>
</article>
<aside>側(cè)邊欄標(biāo)簽</aside>
</article>
<footer>尾部標(biāo)簽</footer>
* {
margin: 0;
padding: 0;
}
.clearF {
clear: both;
}
header,
nav,
article,
footer {
width: 1200px;
background-color: antiquewhite;
border-radius: 15px;
margin: 10px auto;
text-align: center;
}
header {
height: 100px;
line-height: 100px;
}
nav {
height: 50px;
line-height: 50px;
}
article {
background-color: white;
height: 300px;
}
.article1 {
width: 580px;
text-align: center;
background-color: antiquewhite;
border-radius: 15px;
margin: 0;
float: left;
}
aside {
width: 580px;
height: 300px;
line-height: 300px;
background-color: antiquewhite;
border-radius: 15px;
float: right;
}
section {
width: 300px;
height: 50px;
line-height: 50px;
border-radius: 15px;
background-color: white;
margin: auto;
}
footer {
height: 50px;
line-height: 50px;
}
代碼運(yùn)行結(jié)果
語(yǔ)法:
<video src="文件地址"></video>
屬性:
src:視頻文件路徑。
width:播放器寬度。
height:播放器高度。
autoplay:視頻就緒自動(dòng)播放。
controls:向用戶顯示播放控件。
loop:是否循環(huán)播放。
poster:加載等待的畫面圖片。
muted:靜音播放。
代碼練習(xí)
video {
width: 500px;
}
<h3>視頻文件:自動(dòng)播放</h3>
<video src="../images/video.mp4" autoplay="autoplay" muted="muted"></video>
<br>
<h3>視頻文件:添加播放控件</h3>
<video src="../images/video.mp4" autoplay="autoplay" muted="muted" controls="controls"></video>
<br>
<h3>視頻文件設(shè)置循環(huán)播放</h3>
<video src="../images/video.mp4" autoplay="autoplay" muted="muted" controls="controls" loop="loop"></video>
<br>
<h3>視頻文件設(shè)置加載圖片</h3>
<video src="../images/video.mp4" controls="controls" poster="../images/meitizhub.jpg"></video>
語(yǔ)法:
<audio src="文件地址"></audio>
屬性:
src:文件路徑。
autoplay:音頻就緒自動(dòng)播放。
controls:向用戶顯示播放控件。
loop:循環(huán)播放。
代碼練習(xí)
<audio src="../images/audio.mp3" controls="controls"></audio>
<h3>給音頻文件添加循環(huán)播放</h3>
<audio src="../images/audio.mp3" controls="controls" loop="loop"></audio>
屬性值
email:輸入類型為Email類型
url:輸入類型為url類型
date:輸入類型為日期。
time:輸入類型為時(shí)間。
month:輸入類型為月。
week:輸入類型為周。
number:輸入類型為數(shù)字。
tel:輸入類型為手機(jī)號(hào)碼
search:輸入類型為搜索框。
color:生成一個(gè)顏色選擇表單。
<form action="">
<ul>
<li>郵箱:<input type="email"></li>
<li>網(wǎng)址:<input type="url"></li>
<li>日期:<input type="date"></li>
<li>時(shí)間:<input type="time"></li>
<li>月份:<input type="month"></li>
<li>周:<input type="week"></li>
<li>數(shù)量:<input type="number"></li>
<li>手機(jī)號(hào)碼:<input type="tel"></li>
<li>搜索:<input type="search"></li>
<li>顏色:<input type="color"></li>
<li><input type="button" value="提交"></li>
</ul>
</form>
required:內(nèi)容不能為空。
placehoder:提示文本。
autofocus:自動(dòng)聚焦屬性。
autocomplete:on| off 是否顯示歷史輸入。
multiple:提交時(shí)可多選文件。
<form action="">
<input type="srarch" name="srar" id="" required="required" placeholder="請(qǐng)輸入內(nèi)容" autofocus="autofocus" autocomplete="on" >
<input type="file" multiple="multiple">
<input type="submit" value="提交">
</form>
下篇文章學(xué)習(xí)CSS新特性。
編寫HTML5頁(yè)面時(shí),我們很多時(shí)候都需要用到表單屬性,那么HTML5作為一個(gè)新晉IT界紅人,HTML5表單屬性有哪些呢?今天先來(lái)分享一下其中的<form> / <input> autocomplete 屬性、<input> autofocus 屬性、<input> form 屬性以及<input> formaction 屬性。
<form> / <input> autocomplete 屬性
autocomplete 屬性規(guī)定 form 或 input 域應(yīng)該擁有自動(dòng)完成功能。
當(dāng)用戶在自動(dòng)完成域中開(kāi)始輸入時(shí),瀏覽器應(yīng)該在該域中顯示填寫的選項(xiàng)。
提示: autocomplete 屬性有可能在 form元素中是開(kāi)啟的,而在input元素中是關(guān)閉的。
注意: autocomplete 適用于 <form> 標(biāo)簽,以及以下類型的 <input> 標(biāo)簽:text, search, url, telephone, email, password, datepickers, range 以及 color。
實(shí)例
HTML form 中開(kāi)啟 autocomplete (一個(gè) input 字段關(guān)閉 autocomplete ):
<form action="demo-form.php" autocomplete="on">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
E-mail: <input type="email" name="email" autocomplete="off"><br>
<input type="submit">
</form>
提示:某些瀏覽器中,您可能需要啟用自動(dòng)完成功能,以使該屬性生效。
<form> novalidate 屬性
novalidate 屬性的一個(gè)boolean 屬性.
novalidate 屬性規(guī)定在提交表單時(shí)不應(yīng)該驗(yàn)證 form 或 input 域。
實(shí)例
無(wú)需驗(yàn)證提交的表單數(shù)據(jù)
<form action="demo-form.php" novalidate>
E-mail: <input type="email" name="user_email">
<input type="submit">
</form>
<input> autofocus 屬性
autofocus 屬性是一個(gè) boolean 屬性.
autofocus 屬性規(guī)定在頁(yè)面加載時(shí),域自動(dòng)地獲得焦點(diǎn)。
實(shí)例
讓 "First name" input 輸入域在頁(yè)面載入時(shí)自動(dòng)聚焦:
First name:<input type="text" name="fname" autofocus>
<input> form 屬性
form 屬性規(guī)定輸入域所屬的一個(gè)或多個(gè)表單。
提示:如需引用一個(gè)以上的表單,請(qǐng)使用空格分隔的列表。
實(shí)例
位于form表單外的input 字段引用了 HTML form (該 input 表單仍然屬于form表單的一部分):
<form action="demo-form.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
<input> formaction 屬性
The formaction 屬性用于描述表單提交的URL地址.
The formaction 屬性會(huì)覆蓋<form> 元素中的action屬性.
注意: The formaction 屬性用于 type="submit" 和 type="image".
實(shí)例
以下HTMLform表單包含了兩個(gè)不同地址的提交按鈕:
<form action="demo-form.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="demo-admin.php"
value="Submit as admin">
</form>
了解更多計(jì)算機(jī)相關(guān)知識(shí),可登陸北大青鳥(niǎo)廣州新嘉華官網(wǎng)查看,或聯(lián)系在線值班老師了解詳情。
說(shuō)到這個(gè),我們先回顧一下,偽類選擇器和偽元素選擇器,老版的瀏覽器沒(méi)有嚴(yán)格區(qū)分下面 2 種寫法。
a:after{}
a::after{}
在新的標(biāo)準(zhǔn)中,單冒號(hào)(:)用于 CSS3 偽類,雙冒號(hào)(::)用于 CSS3 偽元素,我們平時(shí)開(kāi)發(fā)時(shí)可以注意一下,當(dāng)然大多數(shù)瀏覽器兩種寫法都能識(shí)別。
常見(jiàn)偽元素和偽類偽類
:link, :visited, :hover, :active, :focus, :first-child, :last-child, :nth-child, :nth-last-child, :not()
偽類一般用于一個(gè)元素的某個(gè)狀態(tài),比如說(shuō)鼠標(biāo)懸浮,按鈕點(diǎn)擊,鏈接已經(jīng)訪問(wèn),輸入框聚焦等,還用于選擇某個(gè)特殊元素,比如說(shuō)多個(gè)元素中的第一個(gè),最后一個(gè),偶數(shù),奇數(shù)等。其作用是對(duì)某個(gè)符合以上條件的元素添加一些樣式。
a:hover{
text-decoration: underline;
}
a:active {
color: blue;
}
a:link {
color: red;
}
a:visited {
color: green;
}
上面的例子展示了一個(gè)a標(biāo)簽在不同狀態(tài)下的不同樣式,在未點(diǎn)擊鏈接之前,a標(biāo)簽呈現(xiàn)紅色字體(link),在鼠標(biāo)移到a標(biāo)簽上是,a標(biāo)簽出現(xiàn)下劃線(hover),在鼠標(biāo)按下的時(shí)候,a標(biāo)簽變?yōu)樗{(lán)色(active),點(diǎn)擊完了之后,a標(biāo)簽變?yōu)榫G色(visited)。可以看到,偽類的作用是為了給不同狀態(tài)的標(biāo)簽添加樣式。
::first-letter, ::first-line, ::before, ::after
在內(nèi)容模塊中提到,偽元素如果沒(méi)有設(shè)置“content”屬性,偽元素是無(wú)用的。
使用偽元素插入的內(nèi)容在頁(yè)面的源碼里是不可見(jiàn)的,只能在 css 里可見(jiàn)。
插入的元素在默認(rèn)情況下是內(nèi)聯(lián)元素(或者,在 html5 中,在文本語(yǔ)義的類別里)。因此,為了給插入的元素賦予高度,填充,邊距等等,你通常必須顯式地定義它是一個(gè)塊級(jí)元素。
還要注意的是典型的 CSS 繼承規(guī)則適用于插入的元素。例如,你有字體系列黑體,宋體,無(wú)襯線字體應(yīng)用到 body 元素里,然后偽元素會(huì)像其他元素一樣繼承這些字體系列。
偽元素不會(huì)自然繼承自父元素(如 padding margins)的樣式。
你的直覺(jué)是 :before 和 :after 偽元素可能是插入的內(nèi)容會(huì)被注入到目標(biāo)元素的前或后注入。其實(shí)不是這樣的,注入的內(nèi)容將是有關(guān)聯(lián)的目標(biāo)元素的子元素,但它會(huì)被置于這個(gè)元素的任何內(nèi)容的“前”或“后”。
<head>
<style type="text/css">
p.box::before {
content: "#";
border: solid 1px black;
padding: 2px;
margin: 0 10px 0 0;
}
p.box::after {
content: "#";
border: solid 1px black;
padding: 2px;
margin: 0 10px 0 0;
}
</style>
</head>
<body>
<p class="box">Other content.</p>
</body>
運(yùn)行效果:
可以看到,我們html部分只寫了一個(gè)元素,但是我們利用偽元素渲染出來(lái) 3 個(gè)部分,前中后,這里我們可以認(rèn)為,偽元素一般用來(lái)輔助html的元素。但在內(nèi)容頁(yè)面的源碼又看不到,利用偽元素可以實(shí)現(xiàn)很多神奇的功能,這里不做具體講解,后面再出具體教程。
言歸正傳,回到我們的主角focus-within,我們知道,偽類focus是指一個(gè)元素獲得焦點(diǎn)時(shí),為其添加樣式。focus-within的范圍更廣,它表示一個(gè)元素獲得焦點(diǎn),或該元素的后代元素獲得焦點(diǎn)。劃重點(diǎn),它或它的后代獲得焦點(diǎn)。這也就意味著,它或它的后代獲得焦點(diǎn),都可以觸發(fā) :focus-within。
這個(gè)屬性有點(diǎn)類似 Javascript 的事件冒泡,從可獲焦元素開(kāi)始一直冒泡到根元素 html,都可以接收觸發(fā) :focus-within 事件,類似下面這個(gè)簡(jiǎn)單的例子這樣:
<html>
<div class="box g-father">
<div class="box g-children">
<div class="box button" tabindex="1">button</div>
</div>
</div>
<div class="g-body">HTML</div>
<style>
div {
box-sizing: border-box;
}
.button,.g-children {
width: 100%;
height: 100%;
padding: 20px;
border: 1px solid;
}
.g-father {
width: 200px;
height: 200px;
padding: 20px;
border: 1px solid;
}
.g-body {
margin-top: 20px;
width: 200px;
border: 1px solid;
}
.g-body:focus-within {
background-color: #5daf34;
}
.g-father:focus-within {
background-color: #3a8ee6;
}
.g-children:focus-within{
background-color: #2c3e50;
}
.button:focus-within {
background-color: #606266;
color: red;
}
</style>
</html>
運(yùn)行結(jié)果:
可以看到,在button獲得焦點(diǎn)時(shí),因?yàn)槊芭莸脑颍母讣?jí)元素全部應(yīng)用了:focus-within的樣式。這里值得注意的是,正常的div是不能獲得焦點(diǎn)的,設(shè)置 tabindex 屬性才能獲取焦點(diǎn),同時(shí)按鍵盤 Tab 鍵也可讓其獲取焦點(diǎn),其中 tabindex 的值越小在 tab 鍵切換的時(shí)候就會(huì)首先聚焦。根據(jù):focus-within的特性,我們?cè)诓焕?js 的情況下,實(shí)現(xiàn)很多實(shí)用性的功能。
利用focus-within可以增加用戶的感知區(qū)域,讓用戶獲得更好的視覺(jué)反饋。
<html>
<div class="g-container">
<input type="text" placeholder="user name" class="g_input" >
<input type="text" placeholder="code" class="g_input" >
</div>
<style>
.g-container {
margin-top: 10vh;
}
.g-container {
padding: 10px;
width: 30vw;
border: 1px solid #eee;
transition: all .3s;
text-align: center;
}
.g-container:focus-within {
transform: translateY(-4px);
box-shadow: 0 0 10px #ddd;
border-color: hsl(199, 98%, 48%);
}
.g_input {
border: none;
width: 20vw;
padding: 15px;
font-size: 18px;
box-sizing: border-box;
border: 1px solid #ddd;
overflow: hidden;
transition: 0.3s;
box-shadow: 0 0 0px #ddd;
&:focus {
box-shadow: 0 0 10px #ddd;
border-color: hsl(199, 98%, 48%);
}
}
</style>
</html>
可以看到在沒(méi)有任何javascript邏輯控制情況下,用focus-within就實(shí)現(xiàn)了上面的效果。
我們先看一下效果:
可以看到是一個(gè)很棒的導(dǎo)航效果,而且真?zhèn)€實(shí)現(xiàn)沒(méi)有使用javascript控制,這無(wú)疑在性能和體驗(yàn)上都有不少提升。具體源碼可以看下面的地址:https://codepen.io/dannievinther/pen/NvZjvz
我們平時(shí)可能注意到了,B 站和掘金在用戶輸入密碼的時(shí)候,上面的圖片是捂著眼睛的,這里我們也可以用focus-within來(lái)實(shí)現(xiàn)。
<html>
<div class="g-wrap"></div>
<div class="g-container">
<h2>登錄</h2>
<div class="g-username">
<input maxlength="64" placeholder="請(qǐng)輸入手機(jī)號(hào)或郵箱" class="input">
<img src="https://b-gold-cdn.xitu.io/v3/static/img/greeting.1415c1c.png" class="g-username">
</div>
<div class="g-password">
<input type="password" maxlength="64" placeholder="請(qǐng)輸入密碼" class="input">
<img src="https://b-gold-cdn.xitu.io/v3/static/img/blindfold.58ce423.png" class="g-password">
</div>
<img src="https://b-gold-cdn.xitu.io/v3/static/img/normal.0447fe9.png" class="g-normal">
</div>
<style>
.g-wrap {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0.3);
}
.g-container {
position: relative;
width: 318px;
margin: 100px auto;
height: 370px;
padding: 20px;
box-sizing: border-box;
background: #fff;
z-index: 10;
}
.g-container h2 {
font-size: 20px;
font-weight: bold;
margin-bottom: 30px;
}
.g-container input {
outline: none;
padding: 10px;
width: 100%;
border: 1px solid #e9e9e9;
border-radius: 2px;
outline: none;
box-sizing: border-box;
font-size: 16px;
}
img {
position: absolute;
top: -20%;
left: 50%;
width: 120px;
height: 95px;
transform: translate(-50%, 0);
}
.g-username {
margin-bottom: 10px;
}
.g-username img {
display: none;
width: 120px;
height: 113px;
}
.g-username:focus-within ~ img {
display: none;
}
.g-username:focus-within input {
border-color: #007fff;
}
.g-username:focus-within img {
display: block;
}
.g-password {
margin-bottom: 10px;
}
.g-password img {
display: none;
width: 103px;
height: 84px;
top: -15%;
}
.g-password:focus-within ~ img {
display: none;
}
.g-password:focus-within input {
border-color: #007fff;
}
.g-password:focus-within img {
display: block;
}
</style>
</html>
可以看到,在不適用js的情況下,也能實(shí)現(xiàn)動(dòng)態(tài)切換圖片的效果,但是還是有一些局限,dom排列只能是父級(jí)向上,不能把元素放在focus元素的子元素里面。所以沒(méi)有js靈活,但是代碼量更少。
因?yàn)?css3 的新增特性一直存在兼容問(wèn)題,這里查詢了一下它的兼容性,看到紅色區(qū)域還是不算太慘淡,出來(lái) ie,其他瀏覽器基本都支持了。
所有的源碼都可以在我的倉(cāng)庫(kù)地址:https://github.com/jackzhujie/vue-study
個(gè)人博客:http://blog.aizhifou.cn
文章參考鏈接:https://www.cnblogs.com/coco1s/p/9406413.html
學(xué)習(xí)如逆水行舟,不進(jìn)則退,前端技術(shù)飛速發(fā)展,如果每天不堅(jiān)持學(xué)習(xí),就會(huì)跟不上,我會(huì)陪著大家,每天堅(jiān)持推送博文,跟大家一同進(jìn)步,希望大家能關(guān)注我,第一時(shí)間收到最新文章。
?
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。