各位网友大家好,今天我要带领大家开发一个纯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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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/imghwm/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的不透明度*/}
至此,此页面特效的所有样式代码都编写完了,真心希望大家能受到启发,同时也希望大家喜欢我的教程。
谢谢大家,咱们下个实战开发案例再会。

HTML 코드는 온라인 유효성 검사기, 통합 도구 및 자동화 된 프로세스를 통해 깨끗할 수 있습니다. 1) w3cmarkupvalidationservice를 사용하여 온라인으로 HTML 코드를 확인하십시오. 2) 실시간 확인을 위해 VisualStudioCode에 HTMLHINT 확장을 설치하고 구성하십시오. 3) htmltidy를 사용하여 시공 프로세스에서 HTML 파일을 자동으로 확인하고 청소하십시오.

HTML, CSS 및 JavaScript는 최신 웹 페이지를 구축하기위한 핵심 기술입니다. 1. HTML 웹 페이지 구조를 정의합니다. 2. CSS는 웹 페이지의 모양을 담당합니다.

HTML의 기능은 웹 페이지의 구조와 내용을 정의하는 것이며, 그 목적은 정보를 표시하는 표준화 된 방법을 제공하는 것입니다. 1) HTML은 타이틀 및 단락과 같은 태그 및 속성을 통해 웹 페이지의 다양한 부분을 구성합니다. 2) 콘텐츠 및 성능 분리를 지원하고 유지 보수 효율성을 향상시킵니다. 3) HTML은 확장 가능하므로 사용자 정의 태그가 SEO를 향상시킬 수 있습니다.

HTML의 미래 트렌드는 의미론 및 웹 구성 요소이며 CSS의 미래 트렌드는 CSS-In-JS 및 CSShoudini이며, JavaScript의 미래 트렌드는 WebAssembly 및 서버리스입니다. 1. HTML 시맨틱은 접근성과 SEO 효과를 향상시키고 웹 구성 요소는 개발 효율성을 향상 시키지만 브라우저 호환성에주의를 기울여야합니다. 2. CSS-in-JS는 스타일 관리 유연성을 향상 시키지만 파일 크기를 증가시킬 수 있습니다. CSShoudini는 CSS 렌더링의 직접 작동을 허용합니다. 3. Webosembly는 브라우저 애플리케이션 성능을 최적화하지만 가파른 학습 곡선을 가지고 있으며 서버리스는 개발을 단순화하지만 콜드 스타트 문제의 최적화가 필요합니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. 1. HTML은 웹 페이지 구조를 정의하고, 2. CSS는 웹 페이지 스타일을 제어하고 3. JavaScript는 동적 동작을 추가합니다. 그들은 함께 현대 웹 사이트의 프레임 워크, 미학 및 상호 작용을 구축합니다.

HTML의 미래는 무한한 가능성으로 가득합니다. 1) 새로운 기능과 표준에는 더 많은 의미 론적 태그와 WebComponents의 인기가 포함됩니다. 2) 웹 디자인 트렌드는 반응적이고 접근 가능한 디자인을 향해 계속 발전 할 것입니다. 3) 성능 최적화는 반응 형 이미지 로딩 및 게으른로드 기술을 통해 사용자 경험을 향상시킬 것입니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. HTML은 컨텐츠 구조를 담당하고 CSS는 스타일을 담당하며 JavaScript는 동적 동작을 담당합니다. 1. HTML은 태그를 통해 웹 페이지 구조와 컨텐츠를 정의하여 의미를 보장합니다. 2. CSS는 선택기와 속성을 통해 웹 페이지 스타일을 제어하여 아름답고 읽기 쉽게 만듭니다. 3. JavaScript는 스크립트를 통해 웹 페이지 동작을 제어하여 동적 및 대화식 기능을 달성합니다.

Htmlisnotaprogramminglanguage; itisamarkuplanguage.1) htmlstructuresandformatswebcontentusingtags.2) itworksporstylingandjavaScriptOfforIncincivity, WebDevelopment 향상.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

Dreamweaver Mac版
시각적 웹 개발 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.
