search
HomeWeb Front-endCSS TutorialShare a sample code for a breadcrumb navigation bar with arrows

This article mainly introduces the sample code for making a beautiful and beautiful breadcrumb navigation bar with arrows. Has very good reference value. Let’s take a look at it with the editor

Create a beautiful and beautiful breadcrumb navigation bar

Before starting, I want to give you a popular science as usual about what a breadcrumb navigation bar is

Similar to the following ones

Homepage>Column page>Article page

Homepage/Column page/Article page

Can tell visitors that they are currently on The location in the site and how to return the DOM is called the breadcrumb bar

but. . . . . .

Don’t you think this looks good?

If one day, your company's UI gives you a picture, the breadcrumb navigation bar in the picture looks like this

Like this

Or other patterned breadcrumb navigation bars, what should I do at this time?

Some friends may say that this is so easy, just find a pattern and add a background to the navigation bar.

But is it really that simple? Okay, without further ado, let’s start practicing directly and see how to complete this kind of high-looking bread-shaped navigation bar

1. First use an unordered list to make a navigation bar , the code is as follows


<ul>
    <li>
        <a href="#">主页</a>
    </li>
    <li>
        <a href="#">主页2</a>
    </li>
    <li>
        <a href="#">主页3</a>
    </li>
    <li>
        <a href="#">主页4</a>
    </li>
    <li>
        <a href="#">主页5</a>
    </li>
</ul>

The next is the css code

body{background:#000}
ul{ list-style: none;}
li{
width: 60px;
height: 50px;
line-height: 50px;
float: left;
background: #6cf;
text-align: center;
}
a{
color: #000;
text-decoration: none;
}

The css code is nothing special, just like usual It's almost the same as doing nav. Next, we start to put the background image we selected, which is the picture below

Add a background image to the li in the navigation bar

body{
                background: #000;
            }
            ul{
                list-style: none;
                margin: 100px 100px;
            }
            li{
                width: 60px;
                height: 30px;
                line-height: 30px;
                float: left;
                background: #6cf;
                text-align: center;
                background: url(img/bg.png) no-repeat 100% 0;
            }
            a{
                color: #000;
                text-decoration: none;
            }

This The page effect at that time was like this

Nani? Is there something wrong with this? Director, there's something wrong with this script!

There is indeed a problem, but where is the problem?

Comparing the upper and lower pictures, it is immediately clear where the problem lies. The > of each navigation (except the last one) is piled on the next navigation, then at this time, we only need to add a margin-left:-15px; to the li tag. The specific code is as follows


li{
                width: 80px;
                height: 30px;
                line-height: 30px;
                float: left;
                background: #6cf;
                text-align: center;
                background: url(img/bg.png) no-repeat 100% 0;
                margin-left: -15px;
            }

Since the initial width was not enough, I slightly increased the width of li here. After adding it, our breadcrumb navigation bar became like this

Huh? Where are our arrows?

Where is the arrow you promised?

Where are the arrows 1-4?

Let’s go back to the previous step again. Our last step was to add margin-left to the li tag: -15px;

The front-end stuff has a characteristic, and the attributes written later will usually Overwrite the previous attributes, and the dom structure will not be overwritten, but when the two positions overlap, before the z-index attribute is added, or when the attribute values ​​​​are equal, the dom structure written later will be on top

This is exactly the case here, so we only need to add different z-index separately to the li tag (if you want the z-index attribute to take effect, you must first add positioning, position: relative)

There are no restrictions on the value of z-index here, but there is only one thing, that is, the last li tag is the smallest, and so on, gradually increasing, and the first one is the largest.

The final code looks like this


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            body{
                background: #000;
            }
            ul{
                list-style: none;
                margin: 100px 100px;
            }
            li{
                width: 80px;
                height: 30px;
                line-height: 30px;
                float: left;
                background: #6cf;
                text-align: center;
                background: url(img/bg.png) no-repeat 100% 0;
                margin-left: -15px;
                position: relative;/*保证z-index有效*/
            }
            a{
                color: #000;
                text-decoration: none;
            }
        </style>
    </head>
    <body>
        <ul>
            <li style="z-index: 5;">
                <a href="#">主页</a>
            </li>
            <li style="z-index: 4;">
                <a href="#">主页2</a>
            </li>
            <li style="z-index: 3;">
                <a href="#">主页3</a>
            </li>
            <li style="z-index: 2;">
                <a href="#">主页4</a>
            </li>
            <li style="z-index: 1;">
                <a href="#">主页5</a>
            </li>
        </ul>
    </body>
</html>

The above is the detailed content of Share a sample code for a breadcrumb navigation bar with arrows. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.