惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
AI
AI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
F
Full Disclosure
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Recorded Future
Recorded Future
N
News and Events Feed by Topic
雷峰网
雷峰网
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Project Zero
Project Zero
罗磊的独立博客
G
GRAHAM CLULEY
腾讯CDC
P
Privacy International News Feed
V
V2EX
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
H
Heimdal Security Blog
L
LINUX DO - 热门话题
Forbes - Security
Forbes - Security
美团技术团队
MongoDB | Blog
MongoDB | Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog

CSS Articles by Temani Afif

Get Ready For the Powerful CSS border-shape Property! | CSS-Tricks Let’s Play With Gap Decorations! How to Control Infinite CSS Animations (Part 2 of 2) How to Control Infinite CSS Animations (Part 1 of 2) Two Circles, One Arrow, and Anchor Positioning Making a Responsive Pyramidal Grid With Modern CSS | CSS-Tricks How to Create a CSS-only Elastic Text Effect Making Complex CSS Shapes Using shape() | CSS-Tricks Responsive Hexagon Grid Using Modern CSS | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 2) | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 1) | CSS-Tricks Perfectly Pointed Tooltips: To The Corners Perfectly Pointed Tooltips: All Four Sides Perfectly Pointed Tooltips: A Foundation Sequential linear() Animation With N Elements | CSS-Tricks Infinite Marquee Animation using Modern CSS Better CSS Shapes Using shape() — Part 4: Close and Move | CSS-Tricks Drawing CSS Shapes using corner-shape Better CSS Shapes Using shape() — Part 3: Curves | CSS-Tricks Better CSS Shapes Using shape() — Part 2: More on Arcs | CSS-Tricks Better CSS Shapes Using shape() — Part 1: Lines and Arcs | CSS-Tricks Creating Blob Shapes using clip-path: shape() Creating Flower Shapes using clip-path: shape() Custom progress element using the attr() function A CSS-Only Star Rating Component and More! (Part 2) | CSS-Tricks A CSS-Only Star Rating Component and More! (Part 1) | CSS-Tricks How to Create Wavy Boxes Using CSS Full-Bleed Layout with Modern CSS Fancy Menu Navigation Using Anchor Positioning | CSS-Tricks How to Create a Zig-Zag Box Using CSS How to Create Zig-Zag CSS Loaders Using One Element Custom Progress Element Using Anchor Positioning & Scroll-Driven Animations How to Create Filling CSS Loaders Using One Element How to Create Curved-Edge and Rounded-Edge Shapes Using CSS CSS Tricks That Use Only One Gradient | CSS-Tricks How to create Shapes with Inner Curves using CSS Mask Custom Range Slider Using Anchor Positioning & Scroll-Driven Animations How to Get the Width/Height of Any Element in Only CSS How Keyboard Navigation Works in a CSS Game How To Create Cut-Out Shapes using The clip-path property The Modern Guide For Making CSS Shapes — Smashing Magazine css-shape.com: The Ultimate Collection of CSS-only Shapes ⚡️ Sliding 3D Image Frames In CSS — Smashing Magazine CSS Tricks To Master The clip-path Property Creating Wavy Circles with Fancy Animations in CSS Modern CSS Tooltips And Speech Bubbles (Part 2) — Smashing Magazine Do you need a Tooltip or a Speech Bubble? I have created 100 using CSS 😲 Modern CSS Tooltips And Speech Bubbles (Part 1) — Smashing Magazine Creating Flower Shapes using CSS Mask & Trigonometric Functions CSS Shapes: The Triangle The Complex But Awesome CSS border-image Property — Smashing Magazine CSS Tricks to add 3D Effects to your Text CSS Responsive Multi-Line Ribbon Shapes (Part 2) — Smashing Magazine CSS Responsive Multi-Line Ribbon Shapes (Part 1) — Smashing Magazine I have made 100+ CSS-only Ribbon Shapes | The Perfect Collection 🎀 How to create a CSS-only infinite scroll animation Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 2) — Smashing Magazine Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 1) — Smashing Magazine How to Create CSS Ribbon Shapes with a Single Element CSS Shapes: The Ribbon Revealing Images With CSS Mask Animations — Smashing Magazine css-loaders.com: The Biggest Collection of Loading Animations (more than 500 🤯) How To Define An Array Of Colors With CSS — Smashing Magazine CSS effects on images II Shines, Perspective, And Rotations: Fancy CSS 3D Effects For Images — Smashing Magazine What's your Lucky CSS Pattern? Check It Now! How to Add a CSS Reveal Animation to Your Images Modern Layouts using CSS Grid I created 100+ unique CSS patterns | The best collection 🤩 How to Create a Custom Range Slider Using CSS CSS Shapes: The Heart CSS Shapes: Polygon & Starburst A Text Reveal Animation using CSS CSS Tip: learn CSS the easy way! How to build a CSS-only accordion Different Ways to Get CSS Gradient Shadows | CSS-Tricks A CSS-only responsive Stepper component A Fancy Hover Effect For Your Avatar | CSS-Tricks How to make a zoom effect using CSS Creating a Custom Cursor using CSS CSS Infinite 3D Sliders | CSS-Tricks CSS Infinite Slider Flipping Through Polaroid Images | CSS-Tricks How to create a responsive sidebar menu using CSS CSS Infinite and Circular Rotating Image Slider | CSS-Tricks Making Static Noise From a Weird CSS Gradient Bug | CSS-Tricks CSS Grid and Custom Shapes, Part 3 | CSS-Tricks Fancy Image Decorations: Outlines and Complex Animations | CSS-Tricks Fancy Image Decorations: Masks and Advanced Hover Effects | CSS-Tricks Fancy Image Decorations: Single Element Magic | CSS-Tricks How to create an infinite image slider using CSS How to Create Wavy Shapes & Patterns in CSS | CSS-Tricks How I Made a Pure CSS Puzzle Game | CSS-Tricks How to create a Tooltip/Speech Bubble using CSS CSS Grid and Custom Shapes, Part 2 | CSS-Tricks CSS Grid and Custom Shapes, Part 1 | CSS-Tricks Zooming Images in a Grid Layout | CSS-Tricks How to create a CSS-only loader with one element Exploring CSS Grid’s Implicit Grid and Auto-Placement Powers | CSS-Tricks How to create background pattern using CSS & conic-gradient Single Element Loaders: The Bars | CSS-Tricks
How to create Breadcrumb Navigation with CSS
2023-02-20 · via CSS Articles by Temani Afif

Breadcrumb Navigation with CSS

Written on by Temani AfifWeb Developer

Estimated read time 5 minutes

In a previous article, we build the Stepper component and in this one, we will tackle another famous component: the breadcrumb navigation. I will try to combine modern CSS Tricks to create a breadcrumb system easy to manage and scalable.

CSS Breadcrumb Navigation

The HTML markup

The breadcrumb component can be seen as a navigation system so it’s important to follow a few guidelines to correctly define the HTML to make it accessible

<nav aria-label="Breadcrumb" class="breadcrumb">
  <ol>
    <li>
      <a href="...">Home</a>
    </li>
    <li>
      <a href="...">Page I</a>
    </li>
    <li>
      <a href="...">Page II</a>
    </li>
    <li>
      <a href="" aria-current="page">Current Page</a>
    </li>
  </ol>
</nav>

Most of the code should be self-explanatory. The important thing to notice is the usage of the <nav> element with the aria-label="Breadcrumb" to explicitly define that our navigation is for breadcrumbs and is not the main navigation of the site.

Also, the use of aria-current="page" with the last link indicates that it’s the current page. You can read more about the aria-current on the MDN page.

50%

💰 SAVE 50% ON VERPEX YEARLY MANAGED HOSTING PLANS FOR WORDPRESS

with the discount code

SERVERS-SALE

Styling the Navigation

This is the easiest part of the work. All we have to do is to override the default styles applied to the ol element and consider a configuration where all the items are placed in a row. I will rely on flexbox for this task:

.breadcrumb ol {
  display: flex;
  list-style: none;
  margin: 20px;
  padding: 0;
  gap: 5px;
}

We get the following:

Nothing complex so far so let’s move to the next part.

Styling the links

We will first start with some common styles like background, color, and fonts.

.breadcrumb ol li a { 
  display: block;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  text-decoration: none;
  color: #fff;
  background: #333;
  font-size: 25px;
  font-family: sans-serif;
}
.breadcrumb ol li:last-child a {
  background: #666;
}
.breadcrumb ol li a:focus-visible {
  background: #95c8d9;
}

I am using the :last-child selector to define a different color for the last/current link and :focus-within to define a different color when a link is focused. It’s always important to style the focus state to make the keyboard navigation easy and ensure accessibility.

Links have a default outline on focus but with what we will add next, it won't be visible. For this reason, I considered a background change.

Now, we will use clip-path to create the arrow shapes. Below is a figure to illustrate the polygon we are going to use.

Overview of the clip-path

We have a six-point polygon with a variable S that will control the shape. That variable will be defined as a CSS variable:

.breadcrumb {
  --s: 15px;
}
.breadcrumb ol li {
  clip-path: polygon(0 0,calc(100% - var(--s)) 0,100% 50%,calc(100% - var(--s)) 100%,0 100%,var(--s) 50%);
}

See the Pen by Temani Afif () on .

We are getting close but we still need to rectify a few things. The use of clip-path cut the element from the sides and as we can see in the above demo, the text is also cut. To fix this we have to increase the padding of the links considering the variable S. We will add that value to the left and right padding:

.breadcrumb ol li a { 
  padding: 10px calc(10px + var(--s));
}

We need to also fix the gap between the elements. The gap we defined previously didn’t change but the arrow shape we created with clip-path made the gap looks bigger. To reduce it we can consider some negative margins like the below:

.breadcrumb ol li {
  margin: 0 calc(var(--s)/-2);
}
.breadcrumb ol li:first-child {
  margin-left: 0;
}
.breadcrumb ol li:last-child {
  margin-right: 0;
}

It’s important to disable the negative margin from the left of the first element and the right of the last element to avoid unwanted overflow.

The last fix is to update the polygon of the first element to have a straight edge on the left. To do this we remove the point (S, 50%) from the clip-path

.breadcrumb ol li:first-child {
  clip-path: polygon(0 0,calc(100% - var(--s)) 0,100% 50%,calc(100% - var(--s)) 100%,0 100%);
}

Here is the final demo after applying all the fixes.

50%

💰 SAVE 50% ON VERPEX YEARLY HOSTING PLANS FOR WORDPRESS

with the discount code

AWESOME

Conclusion

We created a nice-looking breadcrumb navigation in no time. As you can see, we used a very simple code and a few clip-path tricks for the arrow shape. All you have to do is to adjust a few values to customize your navigation. Let’s not forget the scalability of this component where you can add as many links as you want.

Frequently Asked Questions

Temani Afif

Temani Afif is an expert web developer, a content creator, and a CSS addict. He is the mastermind behind CSS Loaders, CSS Generators, CSS Tip and many other CSS-related websites.

View more posts by Temani Afif