CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose
各位网友大家好,今天我要带领大家开发一个纯CSS的图片分类显示的网址导航,单纯看标题大家可能有些困惑,依照以往惯例,我先给大家演示一下实际运行效果:
从上面的运行效果,大家不难发现,当我点击某一菜单时,导航区域会相应高亮显示此分类的图标,而其他图标则会变暗。
很多人可能会说,这个这么简单,直接使用javascript或jQuery等前端框架,再配合一些CSS,就可以很快实现同样的效果了。如果你是这一部分人,我也希望你停下脚步,看看这篇教程。因为在今天这篇教程中,我会用另一个思维方式来思考问题,我会带领大家,完全脱离js,怎么来实现切换效果以及实现图片分类,旨在传授给大家一个思想。
好了,废话不多说了,直接开始今天的实战开发教程吧。
首先,我们先定义html页面,代码如下(为了方便演示,我直接导入了styles.css文件,此时文件没任何样式内容):
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="styles.css"> <title>CSS3实战开发:图片过滤分类特效</title> </head> <body> <div class="container"> <div class="hot_navs"> <div class="hot_title"> <input id="selector-type-all" type="radio" name="title_set" class="selector-type-all" checked="checked" /> <label for="selector-type-all" class="label-type-all">全部类别</label> <input id="selector-type-1" type="radio" name="title_set" class="selector-type-1" /> <label for="selector-type-1" class="label-type-1">电子商务</label> <input id="selector-type-2" type="radio" name="title_set" class="selector-type-2" /> <label for="selector-type-2" class="label-type-2">旅游</label> <input id="selector-type-3" type="radio" name="title_set" class="selector-type-3" /> <label for="selector-type-3" class="label-type-3">社交</label> <input id="selector-type-4" type="radio" name="title_set" class="selector-type-4" /> <label for="selector-type-4" class="label-type-4">视频</label> <input id="selector-type-5" type="radio" name="title_set" class="selector-type-5" /> <label for="selector-type-5" class="label-type-5">新闻</label> <input id="selector-type-6" type="radio" name="title_set" class="selector-type-6" /> <label for="selector-type-6" class="label-type-6">信息门户</label> <input id="selector-type-7" type="radio" name="title_set" class="selector-type-7" /> <label for="selector-type-7" class="label-type-7">票务</label> <div class="splitline"></div> <a class="item-type-1" href="http://www.itdriver.cn"> <img src="/static/imghw/default1.png" data-src="imgs/101.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-1" href="http://www.itdriver.cn"> <img src="/static/imghw/default1.png" data-src="imgs/102.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-7" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/103.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <img src="/static/imghw/default1.png" data-src="imgs/104.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-5" href="http://www.itdriver.cn"> <img src="/static/imghw/default1.png" data-src="imgs/105.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-4" href="http://www.itdriver.cn"> <img src="/static/imghw/default1.png" data-src="imgs/106.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-3" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/107.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-4" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/108.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-3" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/109.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-3" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/110.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/111.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/112.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/113.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/114.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-1" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/115.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-5" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/116.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-6" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/117.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> <a class="item-type-2" href="http://www.itdriver.cn"> <i></i> <img src="/static/imghw/default1.png" data-src="imgs/118.png" class="lazy" / alt="CSS3实战开发: 纯CSS实现图片过滤分类显示特效_html/css_WEB-ITnose" > </a> </div> </div> </div> </body></html>
大家从上面的html代码中会发现,我的导航菜单使用了label或radio标签,我为什么要定义它们呢,因为我想知道我当前点击了哪一个菜单,因为单凭CSS,我们貌似没法得到当前点击谁,所以当我点击Label时,会自动的选中某一radio了。
此时我们运行一下页面,看看在未添加任何样式时页面的运行效果:
首先,我们先调整导航区域的大小,以及给导航区域添加边框,样式代码如下:
*{ /*设置页面基本属性*/ margin:0; padding:0; font-size:14px;}.container{ /*调整外围容器布局*/ margin:200px auto; width:1024px;}.hot_navs{ /*设置分类导航样式*/ border:1px solid #CCCCCC; padding:.5em; width:725px;}
此时页面效果如下:
区域范围大小已经定下来了,现在我们要给导航菜单设置样式,隐藏单选按钮,同时设置菜单与图表之间的分割线:
/*分割线*/.hot_navs .splitline { margin-bottom:4px;height:1px;border-top:1px dotted #999999; }.hot_navs a{ /*设置导航item的基本样式*/ text-decoration:none; display:inline-block; height:70px; line-height:70px; position:relative; background:#FFE500; -webkit-transition:all 0.6s; /*当item属性发生变化时,执行过度动画*/ -moz-transition:all 0.6s; -o-transition:all 0.6s; transition:all 0.6s;}.hot_navs input{display:none;}.hot_navs .label-type-all,.hot_navs .label-type-1,.hot_navs .label-type-2,.hot_navs .label-type-3,.hot_navs .label-type-4,.hot_navs .label-type-5,.hot_navs .label-type-6,.hot_navs .label-type-7 { /*设置区域头部导航菜单的基本样式*/ display:inline-block; margin-top:10px; padding:10px 10px; cursor:pointer;}
此时效果如下:
细心的网友会发现,我在上面的CSS样式中添加了transition属性,此属性主要是说,当菜单的任何一个属性发生变化时,执行过渡动画。
接着,我们给导航按钮添加选中时的样式,同时设置,当选择某一菜单时,设置此分类的图标不透明度为1,其它分类的不透明度为0.2,样式代码如下:
.hot_navs input.selector-type-all:checked ~ .label-type-all,.hot_navs input.selector-type-1:checked ~ .label-type-1,.hot_navs input.selector-type-2:checked ~ .label-type-2,.hot_navs input.selector-type-3:checked ~ .label-type-3,.hot_navs input.selector-type-4:checked ~ .label-type-4,.hot_navs input.selector-type-5:checked ~ .label-type-5,.hot_navs input.selector-type-6:checked ~ .label-type-6,.hot_navs input.selector-type-7:checked ~ .label-type-7 { /*设置选择某一菜单时,当前菜单的基本样式*/ font-weight:bold; border-bottom:2px solid #FF9900;}.hot_navs input.selector-type-all:checked ~ a,.hot_navs input.selector-type-1:checked ~ a.item-type-1,.hot_navs input.selector-type-2:checked ~ a.item-type-2,.hot_navs input.selector-type-3:checked ~ a.item-type-3,.hot_navs input.selector-type-4:checked ~ a.item-type-4,.hot_navs input.selector-type-5:checked ~ a.item-type-5,.hot_navs input.selector-type-6:checked ~ a.item-type-6,.hot_navs input.selector-type-7:checked ~ a.item-type-7 { opacity: 1;/*当选择某一类别菜单时,设置当前类别item的不透明度*/}.hot_navs input.selector-type-1:checked ~ a:not(.item-type-1),.hot_navs input.selector-type-2:checked ~ a:not(.item-type-2),.hot_navs input.selector-type-3:checked ~ a:not(.item-type-3),.hot_navs input.selector-type-4:checked ~ a:not(.item-type-4),.hot_navs input.selector-type-5:checked ~ a:not(.item-type-5),.hot_navs input.selector-type-6:checked ~ a:not(.item-type-6),.hot_navs input.selector-type-7:checked ~ a:not(.item-type-7) { opacity: 0.2;/*当选择某一类别菜单时,设置其余类别item的不透明度*/}
至此,此页面特效的所有样式代码都编写完了,真心希望大家能受到启发,同时也希望大家喜欢我的教程。
谢谢大家,咱们下个实战开发案例再会。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

這個AI輔助程式工具在這個AI快速發展的階段,挖掘出了一大批好用的AI輔助程式工具。 AI輔助程式設計工具能夠提升開發效率、提升程式碼品質、降低bug率,是現代軟體開發過程中的重要助手。今天大姚給大家分享4款AI輔助程式工具(而且都支援C#語言),希望對大家有幫助。 https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot是一款AI編碼助手,可幫助你更快、更省力地編寫程式碼,從而將更多精力集中在問題解決和協作上。 Git

使用夸克瀏覽器時,其中有一個過濾重複文件的功能,有些朋友對此還不是很了解,下面為大家介紹一下打開這個功能的操作方法,感興趣的朋友和我一起來看看吧。 1.先在手機中點選「夸克瀏覽器」進入介面後,在頁面中間的選項裡點選選擇「夸克網盤」打開進入。 2.在夸克網盤介面裡下方部分找到“備份設定”,並在上面點擊打開,如下圖所示位置:3.接下來在進入的頁面裡有一個“過濾重複文件”,在它的後面顯示有一個開關按鈕,在上面點擊圓形的滑桿把它設定為彩色即為開啟該功能,繼續備份檔案時將會跳過重複的檔案來節省網盤容量。

2022年3月3日,距離世界首個AI程式設計師Devin誕生不足一個月,普林斯頓大學的NLP團隊開發了一個開源AI程式設計師SWE-agent。它利用GPT-4模型在GitHub儲存庫中自動解決問題。 SWE-agent在SWE-bench測試集上的表現與Devin相似,平均耗時93秒,解決了12.29%的問題。 SWE-agent透過與專用終端交互,可以開啟、搜尋文件內容,使用自動語法檢查、編輯特定行,以及編寫和執行測試。 (註:以上內容為原始內容微調,但保留了原文中的關鍵訊息,未超過指定字數限制。)SWE-A

Go語言開發行動應用程式教學隨著行動應用程式市場的不斷蓬勃發展,越來越多的開發者開始探索如何利用Go語言開發行動應用程式。作為一種簡潔高效的程式語言,Go語言在行動應用開發中也展現了強大的潛力。本文將詳細介紹如何利用Go語言開發行動應用程序,並附上具體的程式碼範例,幫助讀者快速入門並開始開發自己的行動應用程式。一、準備工作在開始之前,我們需要準備好開發環境和工具。首

PHP實戰:快速實現斐波那契數列的程式碼範例斐波那契數列是數學中一個非常有趣且常見的數列,其定義如下:第一個和第二個數為0和1,從第三個數開始,每個數都是前兩個數的和。斐波那契數列的前幾個數字依序為0,1,1.2,3,5,8,13,21,...依此類推。在PHP中,我們可以透過遞歸和迭代兩種方式來實現斐波那契數列的生成。下面我們分別來展示這兩

Android開發是一項繁忙而又令人興奮的工作,而選擇適合的Linux發行版來進行開發則顯得尤為重要。在眾多的Linux發行版中,究竟哪一個最適合Android開發呢?本文將從幾個方面來探討這個問題,並給出具體的程式碼範例。首先,我們來看看目前流行的幾個Linux發行版:Ubuntu、Fedora、Debian、CentOS等,它們都有各自的優點和特點。

《了解VSCode:這款工具到底是用來做什麼的? 》身為程式設計師,無論是初學者或資深開發者,都離不開程式碼編輯工具的使用。在眾多編輯工具中,VisualStudioCode(簡稱VSCode)作為一款開源、輕量級、強大的程式碼編輯器備受開發者歡迎。那麼,VSCode到底是用來做什麼的呢?本文將深入探討VSCode的功能和用途,並提供具體的程式碼範例,以幫助讀者

Go語言作為一種快速、高效的程式語言,在後端開發領域廣受歡迎。然而,很少有人將Go語言與前端開發聯繫起來。事實上,使用Go語言進行前端開發不僅可以提高效率,還能為開發者帶來全新的視野。本文將探討使用Go語言進行前端開發的可能性,並提供具體的程式碼範例,幫助讀者更了解這一領域。在傳統的前端開發中,通常會使用JavaScript、HTML和CSS來建立使用者介面
