CSS3面包屑导航和多步骤指示_html/css_WEB-ITnose
面包屑是用来做当前页面所在的站点位置的导航作用,它一层层的表示站点分类或目录层级关系,而多步骤指示经常用在一些分步流程向导的应用,如分步注册向导,货物订购流程。今天我们来用CSS制作面包屑和多步骤指示的应用。
查看演示 下载源码
HTML
HTML结构非常简单,一个有序列表ol,外面又
面包屑导航条的结构,我们给ol加上class样式为:.cd-breadcrumb,那么当前位置的层级li加上class样式为:.current。
<nav> <ol class="cd-breadcrumb"> <li><a href="#0">首页</a></li> <li><a href="#0">开发</a></li> <li><a href="#0">Web</a></li> <li class="current"><em>技术热点</em></li> </ol></nav>
多步骤指示的结构,我们给ol加上class样式为:.cd-multi-steps,已完成的步骤的li加上class样式:.visited,当前步骤li加上class样式:.current。
<nav> <ol class="cd-multi-steps text-center"> <li class="visited"><a href="#0">购物车</a></li> <li class="visited" ><a href="#0">结算付款</a></li> <li class="current"><em>送货</em></li> <li><em>验货收货</em></li> </ol></nav>
CSS
首先,我们使用::after伪元素来创建分隔符元素,就是层级之间的分割。
.cd-breadcrumb li::after, .cd-multi-steps li::after { display: inline-block; content: '\00bb'; margin: 0 .6em; color: #959fa5;}
如果我们需要使用自定义的分隔符,可以自定义样式 .custom-separator,并将样式添加到
- 元素上,例如:
<nav> <ol class="cd-breadcrumb custom-separator"> <li><a href="#0">首页</a></li> <li><a href="#0">开发</a></li> <li><a href="#0">Web</a></li> <li class="current"><em>技术热点</em></li> </ol></nav>
完了分隔符的样式.custom-separator这样写:
.cd-breadcrumb.custom-separator li::after, .cd-multi-steps.custom-separator li::after { /* replace the default separator with a custom icon */ content: ''; height: 16px; width: 16px; background: url(../img/cd-custom-separator.svg) no-repeat center center; vertical-align: middle;}
如果你像给面包屑导航和分步骤指示加上小图标,可以这些写样式,本例中我们使用svg文件来作图标处理。
.cd-breadcrumb.custom-icons li > *::before, .cd-multi-steps.custom-icons li > *::before { /* add a custom icon before each item */ content: ''; display: inline-block; height: 20px; width: 20px; margin-right: .4em; margin-top: -2px; background: url(../img/cd-custom-icons-01.svg) no-repeat 0 0; vertical-align: middle;}.cd-breadcrumb.custom-icons li:not(.current):nth-of-type(2) > *::before, .cd-multi-steps.custom-icons li:not(.current):nth-of-type(2) > *::before { /* change custom icon using image sprites */ background-position: -20px 0;}.cd-breadcrumb.custom-icons li:not(.current):nth-of-type(3) > *::before, .cd-multi-steps.custom-icons li:not(.current):nth-of-type(3) > *::before { background-position: -40px 0;}.cd-breadcrumb.custom-icons li:not(.current):nth-of-type(4) > *::before, .cd-multi-steps.custom-icons li:not(.current):nth-of-type(4) > *::before { background-position: -60px 0;}.cd-breadcrumb.custom-icons li.current:first-of-type > *::before, .cd-multi-steps.custom-icons li.current:first-of-type > *::before { /* change custom icon for the current item */ background-position: 0 -20px;}.cd-breadcrumb.custom-icons li.current:nth-of-type(2) > *::before, .cd-multi-steps.custom-icons li.current:nth-of-type(2) > *::before { background-position: -20px -20px;}.cd-breadcrumb.custom-icons li.current:nth-of-type(3) > *::before, .cd-multi-steps.custom-icons li.current:nth-of-type(3) > *::before { background-position: -40px -20px;}.cd-breadcrumb.custom-icons li.current:nth-of-type(4) > *::before, .cd-multi-steps.custom-icons li.current:nth-of-type(4) > *::before { background-position: -60px -20px;}
当然,我们也可以将三角形箭头设置成分隔符,代码如下:
.cd-breadcrumb.triangle li::after, .cd-breadcrumb.triangle li > *::after { /* li > *::after is the colored triangle after each item li::after is the white separator between two items */ content: ''; position: absolute; top: 0; left: 100%; content: ''; height: 0; width: 0; /* 48px is the height of the <a> element */ border: 24px solid transparent; border-right-width: 0; border-left-width: 20px; } .cd-breadcrumb.triangle li::after { /* this is the white separator between two items */ z-index: 1; -webkit-transform: translateX(4px); -moz-transform: translateX(4px); -ms-transform: translateX(4px); -o-transform: translateX(4px); transform: translateX(4px); border-left-color: #ffffff; /* reset style */ margin: 0; } .cd-breadcrumb.triangle li > *::after { /* this is the colored triangle after each element */ z-index: 2; border-left-color: inherit; } .cd-breadcrumb.triangle li:last-of-type::after, .cd-breadcrumb.triangle li:last-of-type > *::after { /* hide the triangle after the last step */ display: none; }
对于分步骤指示我们还可以添加class如:.text-center, .text-top和 .text-bottom来让文字的位置对齐,还可以添加class如count用来标记步骤数,如以下代码:
<nav> <ol class="cd-multi-steps text-bottom count"> <li class="visited"><a href="#0">购物车</a></li> <li class="visited" ><a href="#0">结算付款</a></li> <li class="current"><em>送货</em></li> <li><em>验货收货</em></li> </ol></nav>
各种添加的样式具体可以看演示demo,我们的demo中给出9种不同的示例,查看页面源代码你就会有收获。

핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

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

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

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











이 기사는 HTML & lt; Progress & Gt에 대해 설명합니다. 요소, 그 목적, 스타일 및 & lt; meter & gt의 차이; 요소. 주요 초점은 & lt; progress & gt; 작업 완료 및 & lt; meter & gt; Stati의 경우

이 기사는 HTML & LT; Datalist & GT에 대해 논의합니다. 자동 완성 제안을 제공하고, 사용자 경험을 향상시키고, 오류를 줄임으로써 양식을 향상시키는 요소. 문자 수 : 159

이 기사는 HTML & lt; meter & gt에 대해 설명합니다. 범위 내에 스칼라 또는 분수 값을 표시하는 데 사용되는 요소 및 웹 개발의 일반적인 응용 프로그램. & lt; meter & gt; & lt; Progress & Gt; 그리고 Ex

이 기사는 모바일 장치의 반응 형 웹 디자인에 필수적인 Viewport Meta Tag에 대해 설명합니다. 적절한 사용이 최적의 컨텐츠 스케일링 및 사용자 상호 작용을 보장하는 방법을 설명하는 반면, 오용은 설계 및 접근성 문제로 이어질 수 있습니다.

이 기사는 html5 & lt; time & gt; 시맨틱 날짜/시간 표현 요소. 인간이 읽을 수있는 텍스트와 함께 기계 가독성 (ISO 8601 형식)에 대한 DateTime 속성의 중요성을 강조하여 Accessibilit를 향상시킵니다.

기사는 HTML5 크로스 브라우저 호환성을 보장하기위한 모범 사례에 대해 논의하고 기능 감지, 점진적 향상 및 테스트 방법에 중점을 둡니다.

이 기사에서는 브라우저에서 직접 사용자 입력을 검증하기 위해 필요한, Pattern, Min, Max 및 Length 한계와 같은 HTML5 양식 검증 속성을 사용하는 것에 대해 설명합니다.

이 기사는 & lt; iframe & gt; 외부 컨텐츠를 웹 페이지, 공통 용도, 보안 위험 및 객체 태그 및 API와 같은 대안을 포함시키는 태그의 목적.
