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
起html的錨點(diǎn)這個(gè)概念,你可能會(huì)感到會(huì)陌生,感覺自己沒有聽過。但是如果說起它的作用,你可能就恍然大悟了,就像你說起一個(gè)演員,可能不知道是誰,但是說起它演的一個(gè)角色可能立馬就知道那個(gè)人是誰了。
那么,什么是錨點(diǎn)呢?
錨點(diǎn)存在于html中,在默認(rèn)情況下,可以快速的定位到指定元素,并將元素置于頁面最頂端。當(dāng)然我們可以按照自己的需求來確定錨點(diǎn)的位置,不一定要讓其定位在頂部?,F(xiàn)如今有無數(shù)多的頁面已經(jīng)用上了錨點(diǎn),比如Vue.js的官網(wǎng),在我們點(diǎn)擊標(biāo)題“Vue.js是什么”和標(biāo)題“起步”的時(shí)候,標(biāo)題都會(huì)自動(dòng)移到頁面頂端。
錨點(diǎn)的使用
那接下來,我們就來看看幾種錨點(diǎn)的使用方法。
id定位
最基本的使用方法如下,當(dāng)點(diǎn)擊<a>標(biāo)簽時(shí),頁面會(huì)相應(yīng)的將該div內(nèi)容置頂
錨點(diǎn)的id定位方法
name定位
除了id,還可以通過name進(jìn)行定位,不過需要主要的是,如果采用name屬性進(jìn)行定位的話,只適用于a標(biāo)簽,類似于p標(biāo)簽等都不支持。
錨點(diǎn)的name定位方法
javascript代碼進(jìn)行定位
在原生的javascript中,有一個(gè)scrollIntoView()方法,可以實(shí)現(xiàn)頁面的錨點(diǎn)
javascript方法實(shí)現(xiàn)錨點(diǎn)
一個(gè)綜合的例子
講了三種實(shí)現(xiàn)方法后,接下來看一個(gè)實(shí)際運(yùn)用的例子。首先是實(shí)際效果圖,在點(diǎn)擊左側(cè)欄時(shí),頁面右邊會(huì)相應(yīng)的顯示指定段落的內(nèi)容
錨點(diǎn)的實(shí)際使用
首先看下html頁面的內(nèi)容,左側(cè)的ul代碼
左側(cè)的ul代碼
右側(cè)的內(nèi)容部分代碼
右側(cè)內(nèi)容部分代碼
css部分的代碼
css部分的代碼
將上述的代碼寫在一個(gè)html文件中,便可實(shí)現(xiàn)左側(cè)欄點(diǎn)擊,右側(cè)欄顯示相應(yīng)內(nèi)容的效果。
特殊情況
在實(shí)際項(xiàng)目中,我們總會(huì)遇到這樣一種情況,在頁面頂部有固定頭內(nèi)容的時(shí)候,如果直接使用上述方法,會(huì)得不到想要的效果
直接使用錨點(diǎn)的效果圖
通過該圖可以看出,第三段內(nèi)容的標(biāo)題被遮住了,實(shí)際應(yīng)該往下再顯示一點(diǎn)
那么,我們?cè)撛趺唇鉀Q這個(gè)問題呢?在這里我想到了兩種方法,第一種是在每個(gè)內(nèi)容div上加一個(gè)隱藏的p元素,給p元素一個(gè)定高,再向上偏移,這種方法會(huì)導(dǎo)致頁面出現(xiàn)很多個(gè)多余的p元素,不推薦使用。
第二種是利用偽元素,偽元素可以占用實(shí)際的高度,這是推薦使用的方法
偽元素的樣式
通過給h3標(biāo)簽添加偽元素樣式,可完美解決這個(gè)問題,效果圖如下
使用偽元素后的效果圖
總結(jié)
今天的內(nèi)容你會(huì)了么?如果還沒有掌握的話,可以按照文章中的代碼,進(jìn)行實(shí)踐,代碼總是要多敲才更容易理解。
如果喜歡的話,記得關(guān)注小編噢,小編后續(xù)會(huì)堅(jiān)持出更多技術(shù)性的文章,如果有任何問題,也歡迎提問,小編都會(huì)盡力解答的。
天查Html手冊(cè)時(shí),又有了新的發(fā)現(xiàn)。也就這機(jī)會(huì),好好總結(jié)下HTML中Meta的使用。
HTML <meta> 標(biāo)簽,所有瀏覽器都支持 <meta> 標(biāo)簽。它提供關(guān)于HTML文檔的元數(shù)據(jù)。元數(shù)據(jù)不會(huì)顯示在頁面上,但是對(duì)于機(jī)器是可讀的。它可用于瀏覽器(如何顯示內(nèi)容或重新加載頁面),對(duì)搜索引擎和更新頻度的描述和關(guān)鍵詞,或其他 web 服務(wù)。
<meta> 標(biāo)簽位于文檔的頭部,不包含任何內(nèi)容。<meta> 標(biāo)簽的屬性定義了與文檔相關(guān)聯(lián)的名稱/值對(duì)。
在 HTML 中,<meta> 標(biāo)簽沒有結(jié)束標(biāo)簽,在 XHTML 中,<meta> 標(biāo)簽必須被正確地關(guān)閉。
必要屬性
屬性值描述contentsome text定義與http-equiv或name屬性相關(guān)的元信息
可選屬性
屬性值描述http-equivcontent-type / expire / refresh / set-cookie把content屬性關(guān)聯(lián)到HTTP頭部。nameauthor / description / keywords / generator / revised / others把 content 屬性關(guān)聯(lián)到一個(gè)名稱。contentsome text定義用于翻譯 content 屬性值的格式。
關(guān)鍵詞:類似這樣的 meta 標(biāo)簽可能對(duì)于進(jìn)入搜索引擎的索引有幫助.使用人們可能會(huì)搜索,并準(zhǔn)確描述網(wǎng)頁上所提供信息的描述性和代表性關(guān)鍵字及短語。標(biāo)記內(nèi)容太短,則搜索引擎可能不會(huì)認(rèn)為這些內(nèi)容相關(guān),標(biāo)記不應(yīng)超過 874 個(gè)字符。
<meta name="keywords" content="HTML,ASP,PHP,SQL">
頁面描述,每個(gè)網(wǎng)頁都應(yīng)有一個(gè)不超過 150 個(gè)字符且能準(zhǔn)確反映網(wǎng)頁內(nèi)容的描述標(biāo)簽
<meta name="description" content="your description">
搜索引擎索引方式,robotterms是一組使用逗號(hào)(,)分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。確保正確使用nofollow和noindex屬性值。
<meta name="robots" content="index,follow" />
<!--
all:文件將被檢索,且頁面上的鏈接可以被查詢;
none:文件將不被檢索,且頁面上的鏈接不可以被查詢;
index:文件將被檢索;
follow:頁面上的鏈接可以被查詢;
noindex:文件將不被檢索;
nofollow:頁面上的鏈接不可以被查詢。
-->
頁面重定向和刷新:content內(nèi)的數(shù)字代表時(shí)間(秒),既多少時(shí)間后刷新。如果加url,則會(huì)重定向到指定網(wǎng)頁(搜索引擎能夠自動(dòng)檢測(cè),也很容易被引擎視作誤導(dǎo)而受到懲罰)。
<meta http-equiv="Refresh" content="5;url=http://www.w3school.com.cn" /><!--5秒鐘后跳轉(zhuǎn)到http://www.w3school.com.cn-->
<meta http-equiv="Refresh" content="5;" /><!--每5秒鐘刷新一下頁面-->
viewport:能優(yōu)化移動(dòng)瀏覽器的顯示。如果不是響應(yīng)式網(wǎng)站,不要使用initial-scale或者禁用縮放。大部分4.7-5寸設(shè)備的viewport寬設(shè)為360px;5.5寸設(shè)備設(shè)為400px;iphone6設(shè)為375px;ipone6 plus設(shè)為414px。很多人使用initial-scale=1到非響應(yīng)式網(wǎng)站上,這會(huì)讓網(wǎng)站以100%寬度渲染,用戶需要手動(dòng)移動(dòng)頁面或者縮放。如果和initial-scale=1同時(shí)使用user-scalable=no或maximum-scale=1,則用戶將不能放大/縮小網(wǎng)頁來看到全部的內(nèi)容。
content 參數(shù):
width viewport 寬度(數(shù)值/device-width)
height viewport 高度(數(shù)值/device-height)
initial-scale 初始縮放比例
maximum-scale 最大縮放比例
minimum-scale 最小縮放比例
user-scalable 是否允許用戶縮放(yes/no)
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
<!-- `width=device-width` 會(huì)導(dǎo)致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時(shí)出現(xiàn)黑邊 -->
各瀏覽器平臺(tái)
Microsoft Internet Explorer
<!-- 優(yōu)先使用最新的ie版本 -->
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-- 是否開啟cleartype顯示效果 -->
<meta http-equiv="cleartype" content="on">
<meta name="skype_toolbar" content="skype_toolbar_parser_compatible"><!-- 關(guān)于X-UA-Compatible -->
<meta http-equiv="X-UA-Compatible" content="IE=6" ><!-- 使用IE6 -->
<meta http-equiv="X-UA-Compatible" content="IE=7" ><!-- 使用IE7 -->
<meta http-equiv="X-UA-Compatible" content="IE=8" ><!-- 使用IE8 --><!-- Pinned Site -->
<!-- IE 10 / Windows 8 -->
<meta name="msapplication-TileImage" content="pinned-tile-144.png">
<meta name="msapplication-TileColor" content="#009900">
<!-- IE 11 / Windows 9.1 -->
<meta name="msapplication-config" content="ieconfig.xml">
Google Chrome
<!-- 優(yōu)先使用最新的chrome版本 -->
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<!-- 禁止自動(dòng)翻譯 -->
<meta name="google" value="notranslate">
360瀏覽器
<!-- 選擇使用的瀏覽器解析內(nèi)核 -->
<meta name="renderer" content="webkit|ie-comp|ie-stand">
UC手機(jī)瀏覽器
<!-- 將屏幕鎖定在特定的方向 -->
<meta name="screen-orientation" content="landscape/portrait">
<!-- 全屏顯示頁面 -->
<meta name="full-screen" content="yes">
<!-- 強(qiáng)制圖片顯示,即使是"text mode" -->
<meta name="imagemode" content="force">
<!-- 應(yīng)用模式,默認(rèn)將全屏,禁止長按菜單,禁止手勢(shì),標(biāo)準(zhǔn)排版,強(qiáng)制圖片顯示。 -->
<meta name="browsermode" content="application">
<!-- 禁止夜間模式顯示 -->
<meta name="nightmode" content="disable">
<!-- 使用適屏模式顯示 -->
<meta name="layoutmode" content="fitscreen">
<!-- 當(dāng)頁面有太多文字時(shí)禁止縮放 -->
<meta name="wap-font-scale" content="no">
QQ手機(jī)瀏覽器
<!-- 鎖定屏幕在特定方向 -->
<meta name="x5-orientation" content="landscape/portrait">
<!-- 全屏顯示 -->
<meta name="x5-fullscreen" content="true">
<!-- 頁面將以應(yīng)用模式顯示 -->
<meta name="x5-page-mode" content="app">
Apple iOS
<!-- Smart App Banner -->
<meta name="apple-itunes-app" content="app-id=APP_ID,affiliate-data=AFFILIATE_ID,app-argument=SOME_TEXT">
<!-- 禁止自動(dòng)探測(cè)并格式化手機(jī)號(hào)碼 -->
<meta name="format-detection" content="telephone=no">
<!-- Add to Home Screen添加到主屏 -->
<!-- 是否啟用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- 設(shè)置狀態(tài)欄的背景顏色,只有在 “apple-mobile-web-app-capable” content=”yes” 時(shí)生效 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!-- 添加到主屏后的標(biāo)題 -->
<meta name="apple-mobile-web-app-title" content="App Title">
Google Android
<meta name="theme-color" content="#E64545">
<!-- 添加到主屏 -->
<meta name="mobile-web-app-capable" content="yes">
<!-- More info: https://developer.chrome.com/multidevice/android/installtohomescreen -->
App Links<!-- iOS -->
<meta property="al:ios:url" content="applinks://docs">
<meta property="al:ios:app_store_id" content="12345">
<meta property="al:ios:app_name" content="App Links">
<!-- Android -->
<meta property="al:android:url" content="applinks://docs">
<meta property="al:android:app_name" content="App Links">
<meta property="al:android:package" content="org.applinks">
<!-- Web Fallback -->
<meta property="al:web:url" content="http://applinks.org/documentation">
<!-- More info: http://applinks.org/documentation/ -->
其它常用的meta
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection"content="telephone=no, email=no" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" /><!-- 刪除蘋果默認(rèn)的工具欄和菜單欄 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black" /><!-- 設(shè)置蘋果工具欄顏色 -->
<meta name="format-detection" content="telphone=no, email=no" /><!-- 忽略頁面中的數(shù)字識(shí)別為電話,忽略email識(shí)別 -->
<!-- 啟用360瀏覽器的極速模式(webkit) -->
<meta name="renderer" content="webkit">
<!-- 避免IE使用兼容模式 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 針對(duì)手持設(shè)備優(yōu)化,主要是針對(duì)一些老的不識(shí)別viewport的瀏覽器,比如黑莓 -->
<meta name="HandheldFriendly" content="true">
<!-- 微軟的老式瀏覽器 -->
<meta name="MobileOptimized" content="320">
<!-- uc強(qiáng)制豎屏 -->
<meta name="screen-orientation" content="portrait">
<!-- QQ強(qiáng)制豎屏 -->
<meta name="x5-orientation" content="portrait">
<!-- UC強(qiáng)制全屏 -->
<meta name="full-screen" content="yes">
<!-- QQ強(qiáng)制全屏 -->
<meta name="x5-fullscreen" content="true">
<!-- UC應(yīng)用模式 -->
<meta name="browsermode" content="application">
<!-- QQ應(yīng)用模式 -->
<meta name="x5-page-mode" content="app">
<!-- windows phone 點(diǎn)擊無高光 -->
<meta name="msapplication-tap-highlight" content="no">
<!-- 適應(yīng)移動(dòng)端end -->
網(wǎng)頁編碼:以下兩種charset定義方式均可
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
禁止緩存:禁止瀏覽器從本地機(jī)的緩存中調(diào)閱頁面內(nèi)容,網(wǎng)頁不保存在緩存中,每次訪問都刷新頁面。這樣設(shè)定,訪問者將無法脫機(jī)瀏覽
<meta http-equiv="Pragma" content="no-cache">
網(wǎng)頁過期:指定網(wǎng)頁在緩存中的過期時(shí)間,一旦網(wǎng)頁過期,必須到服務(wù)器上重新調(diào)閱。注意:必須使用GMT的時(shí)間格式,或直接設(shè)為0(數(shù)字表示多少時(shí)間后過期)
<Meta http-equiv="Expires" Content="Wed, 26 Feb 1997 08:21:57 GMT">
Cookie設(shè)置:注意:必須使用GMT的時(shí)間格式
<Meta http-equiv="Set-Cookie" Content="cookievalue=xxx; expires=Wednesday,21-Oct-98 16:14:21 GMT; path=/">
顯示窗口的設(shè)定:強(qiáng)制頁面在當(dāng)前窗口以獨(dú)立頁面顯示,這個(gè)屬性是用來防止別人在框架里調(diào)用你的頁面。Content選項(xiàng):_blank、_top、_self、_parent.
<Meta http-equiv="Widow-target" Content="_top">
進(jìn)入與退出:這個(gè)是頁面被載入和調(diào)出時(shí)的一些特效。這個(gè)有好多特效,可以查詢Page-Exit去了解更多。
<Meta http-equiv="Page-Exit" Content="blendTrans(Duration=0.5)">
內(nèi)容安全策略CSP(Content-Security-Policy),可以參考https://blog.csdn.net/u014465934/article/details/84199171
<meta http-equiv="Content-Security-Policy" content="script-src 'self'">
喜歡小編的可以點(diǎn)個(gè)贊關(guān)注小編哦,小編每天都會(huì)給大家分享文章。
我自己是一名從事了多年的前端老程序員,小編為大家準(zhǔn)備了新出的前端編程學(xué)習(xí)資料,免費(fèi)分享給大家!
如果你也想學(xué)習(xí)前端,可以觀看【置頂】文章。也可以私信【1】拿
部分主要涉及兩個(gè)內(nèi)容:置頂和列表分類。
1. 置頂
一般的論壇都會(huì)有帖子置頂功能。現(xiàn)在我們?cè)谕ㄖ惲斜碇性黾又庙敼δ堋?/p>
要求置頂在最上,其他按照發(fā)布時(shí)間降序排列。因此修改表,增加一個(gè)sort字段,表示排序,0表示置頂
2. 排序
修改controller類中的getNotices方法。
3. 前端展示
修改NoticeList.vue
4. 字典
上面的例子中,首頁顯示了10條最新通知。這個(gè)10是寫在代碼中的,顯然這是不合適的,無法動(dòng)態(tài)修改。解決這個(gè)問題的方法是,將這個(gè)數(shù)據(jù)記錄在數(shù)據(jù)庫中,并可以在程序的后臺(tái)管理中(后續(xù)開發(fā))動(dòng)態(tài)設(shè)置。為此建立一個(gè)字典表,記錄這個(gè)值。
哪些內(nèi)容可以放到字典中:
性別。因?yàn)樾詣e不會(huì)變動(dòng),但是用戶信息會(huì)用到。
首頁通知條數(shù)。每次打開首頁都會(huì)用到。允許變動(dòng),但很少會(huì)變動(dòng)。
新建dict實(shí)體類和jpa接口
新建Constant類,用于記錄數(shù)據(jù)字典數(shù)據(jù)的標(biāo)記,以便在程序各個(gè)模塊中保持調(diào)用一致。
修改Controller類中的getNotices()方法
修改數(shù)據(jù)字典中相應(yīng)值為5,同時(shí)前端界面做了調(diào)整
5. 問題列表
展示同學(xué)們針對(duì)課程的問題和回復(fù)。因?yàn)檎n程涉及很多內(nèi)容,比如Java、Mysql、Tomcat、HTML、JavaScript,還有Spring Boot、VUE、Element UI等,所以對(duì)問題,需要進(jìn)行分類,以便后續(xù)的查詢和統(tǒng)計(jì)。
Question表
分類表
分類樹
對(duì)照表,首頁用不到
回復(fù)表
6. Sql語句
這里涉及到了兩個(gè)技術(shù)問題
Jpa中如何使用原生sql
為返回字段單獨(dú)建立一個(gè)返回值接口 QuestionIndex。
7. 返回的json數(shù)據(jù)
8. 前端顯示
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。