麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開(kāi)發(fā) > CSS > 正文

20 個(gè) CSS 高級(jí)技巧匯總(推薦)

2024-07-11 09:07:57
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

使用技巧會(huì)讓人變的越來(lái)越懶,沒(méi)錯(cuò),我就是想讓你變懶。下面是我收集的CSS高級(jí)技巧,希望你懶出境界。

1. 黑白圖像

這段代碼會(huì)讓你的彩色照片顯示為黑白照片,是不是很酷?

img.desaturate {    filter: grayscale(100%);    -webkit-filter: grayscale(100%);    -moz-filter: grayscale(100%);    -ms-filter: grayscale(100%);    -o-filter: grayscale(100%);}

2. 使用 :not() 在菜單上應(yīng)用/取消應(yīng)用邊框

先給每一個(gè)菜單項(xiàng)添加邊框

/* add border */.nav li {  border-right: 1px solid #666;}……然后再除去最后一個(gè)元素……// remove border /.nav li:last-child {  border-right: none;}……可以直接使用 :not() 偽類來(lái)應(yīng)用元素:.nav li:not(:last-child) {  border-right: 1px solid #666;}

這樣代碼就干凈,易讀,易于理解了。

當(dāng)然,如果你的新元素有兄弟元素的話,也可以使用通用的兄弟選擇符(~):

.nav li:first-child ~ li {  border-left: 1px solid #666;}

3. 頁(yè)面頂部陰影

下面這個(gè)簡(jiǎn)單的 CSS3 代碼片段可以給網(wǎng)頁(yè)加上漂亮的頂部陰影效果:

body:before {          content: "";          position: fixed;          top: -10px;          left: 0;          width: 100%;          height: 10px;          -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,.8);          -moz-box-shadow: 0px 0px 10px rgba(0,0,0,.8);          box-shadow: 0px 0px 10px rgba(0,0,0,.8);          z-index: 100;}

4. 給 body 添加行高

你不需要分別添加 line-height 到每個(gè)p,h標(biāo)記等。只要添加到 body 即可:

body {  line-height: 1;}

這樣文本元素就可以很容易地從 body 繼承。

5. 所有一切都垂直居中

要將所有元素垂直居中,太簡(jiǎn)單了:

html, body {  height: 100%;  margin: 0;}body {  -webkit-align-items: center;    -ms-flex-align: center;    align-items: center;  display: -webkit-flex;  display: flex;}

看,是不是很簡(jiǎn)單。

注意:在IE11中要小心flexbox。

6. 逗號(hào)分隔的列表

讓HTML列表項(xiàng)看上去像一個(gè)真正的,用逗號(hào)分隔的列表:

ul > li:not(:last-child)::after {  content: ",";}

對(duì)最后一個(gè)列表項(xiàng)使用 :not() 偽類。

7. 使用負(fù)的 nth-child 選擇項(xiàng)目

在CSS中使用負(fù)的 nth-child 選擇項(xiàng)目1到項(xiàng)目n。

li {  display: none;}/* select items 1 through 3 and display them */li:nth-child(-n+3) {  display: block;}

8. 對(duì)圖標(biāo)使用 SVG

我們沒(méi)有理由不對(duì)圖標(biāo)使用SVG:

.logo {  background: url("logo.svg");}

SVG對(duì)所有的分辨率類型都具有良好的擴(kuò)展性,并支持所有瀏覽器都回歸到IE9。這樣可以避開(kāi).png、.jpg或.gif文件了。

9. 優(yōu)化顯示文本

有時(shí),字體并不能在所有設(shè)備上都達(dá)到最佳的顯示,所以可以讓設(shè)備瀏覽器來(lái)幫助你:

html {  -moz-osx-font-smoothing: grayscale;  -webkit-font-smoothing: antialiased;  text-rendering: optimizeLegibility;}

注:請(qǐng)負(fù)責(zé)任地使用 optimizeLegibility。此外,IE /Edge沒(méi)有 text-rendering 支持。

10. 對(duì)純 CSS 滑塊使用 max-height

使用 max-height 和溢出隱藏來(lái)實(shí)現(xiàn)只有CSS的滑塊:

.slider ul {  max-height: 0;  overlow: hidden;}.slider:hover ul {  max-height: 1000px;  transition: .3s ease;}

11. 繼承 box-sizing

讓 box-sizing 繼承 html:

html {  box-sizing: border-box;}*, *:before, *:after {  box-sizing: inherit;}

這樣在插件或杠桿其他行為的其他組件中就能更容易地改變 box-sizing 了。

12. 表格單元格等寬

表格工作起來(lái)很麻煩,所以務(wù)必盡量使用 table-layout: fixed 來(lái)保持單元格的等寬:

.calendar {  table-layout: fixed;}

13. 用 Flexbox 擺脫外邊距的各種 hack

當(dāng)需要用到列分隔符時(shí),通過(guò)flexbox的 space-between 屬性,你就可以擺脫nth-,first-,和 last-child 的hack了:

.list {  display: flex;  justify-content: space-between;}.list .person {  flex-basis: 23%;}

現(xiàn)在,列表分隔符就會(huì)在均勻間隔的位置出現(xiàn)。

14. 使用屬性選擇器用于空鏈接

當(dāng)a元素沒(méi)有文本值,但 href 屬性有鏈接的時(shí)候顯示鏈接:

a[href^="http"]:empty::before {  content: attr(href);}

相當(dāng)方便。

15. 檢測(cè)鼠標(biāo)雙擊

HTML:

<div class="test3">  <span><input type="text" value=" " readonly="true" />  <a href="http://renpingjun.com">Double click me</a></span></div>

CSS:

.test3 span {  position: relative;}.test3 span a {  position: relative;  z-index: 2;}.test3 span a:hover, .test3 span a:active {  z-index: 4;}.test3 span input {  background: transparent;  border: 0;  cursor: pointer;  position: absolute;  top: -1px;  left: 0;  width: 101%;  /* Hacky */  height: 301%; /* Hacky */  z-index: 3;}.test3 span input:focus {  background: transparent;  border: 0;  z-index: 1;}

16. CSS 寫(xiě)出三角形

/* create an arrow that points up */div.arrow-up {  width:0px;  height:0px;  border-left:5px solid transparent;  /* left arrow slant */  border-right:5px solid transparent; /* right arrow slant */  border-bottom:5px solid #2f2f2f; /* bottom, add background color here */  font-size:0px;  line-height:0px;}/* create an arrow that points down */div.arrow-down {  width:0px;  height:0px;  border-left:5px solid transparent;  border-right:5px solid transparent;  border-top:5px solid #2f2f2f;  font-size:0px;  line-height:0px;}/* create an arrow that points left */div.arrow-left {  width:0px;  height:0px;  border-bottom:5px solid transparent;  /* left arrow slant */  border-top:5px solid transparent; /* right arrow slant */  border-right:5px solid #2f2f2f; /* bottom, add background color here */  font-size:0px;  line-height:0px;}/* create an arrow that points right */div.arrow-right {  width:0px;  height:0px;  border-bottom:5px solid transparent;  /* left arrow slant */  border-top:5px solid transparent; /* right arrow slant */  border-left:5px solid #2f2f2f; /* bottom, add background color here */  font-size:0px;  line-height:0px;}

17. CSS3 calc() 的使用

calc() 用法類似于函數(shù),能夠給元素設(shè)置動(dòng)態(tài)的值:

/* basic calc */.simpleBlock {  width: calc(100% - 100px);}/* calc in calc */.complexBlock {  width: calc(100% - 50% / 3);  padding: 5px calc(3% - 2px);  margin-left: calc(10% + 10px);}

18. 文本漸變

文本漸變效果很流行,使用 CSS3 能夠很簡(jiǎn)單就實(shí)現(xiàn):

h2[data-text] {  position: relative;}h2[data-text]::after {  content: attr(data-text);  z-index: 10;  color: #e3e3e3;  position: absolute;  top: 0;  left: 0;  -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,0)), color-stop(50%, rgba(0,0,0,1)), to(rgba(0,0,0,0)));}

19. 禁用鼠標(biāo)事件

CSS3 新增的 pointer-events 讓你能夠禁用元素的鼠標(biāo)事件,例如,一個(gè)連接如果設(shè)置了下面的樣式就無(wú)法點(diǎn)擊了。

.disabled { pointer-events: none; }

20. 模糊文本

簡(jiǎn)單但很漂亮的文本模糊效果,簡(jiǎn)單又好看!

.blur {   color: transparent;   text-shadow: 0 0 5px rgba(0,0,0,0.5);}

總結(jié)

以上所述是小編給大家介紹的20 個(gè) CSS 高級(jí)技巧匯總(推薦),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到CSS教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 一级国产航空美女毛片内谢 | 亚洲精品久久久久久久久久 | 色淫影院 | 九一免费国产 | 99国产精品欲a | 国产做爰全免费的视频黑人 | 黄色成人短视频 | 青青国产在线视频 | 久久人人97超碰国产公开结果 | 久久精品视频2 | 免费一区二区三区 | 久久精品日产高清版的功能介绍 | 国产精品啪一品二区三区粉嫩 | 成人在线视频网 | 特黄一级小说 | 黄色毛片18 | 亚洲一级网站 | 久久久久免费电影 | 色a综合 | 97se亚洲综合在线韩国专区福利 | 青青草成人免费视频在线 | 久久不雅视频 | 亚洲天堂中文字幕在线观看 | 免费欧美一级视频 | 午夜精品久久久久久久久久久久久蜜桃 | 国产高潮好爽好大受不了了 | 欧美一级在线看 | 中日韩免费视频 | 国产激情视频在线 | 羞羞的视频在线免费观看 | 国产美女自拍av | 性 毛片 | 久久久成人精品视频 | 亚州精品国产 | 欧美性成人 | 国产在线精品一区二区三区 | 国产精品呻吟 | 亚洲第一激情 | 看免费5xxaaa毛片 | 欧美精品videos | 毛片免费大全短视频 |