Implement a popmenu for navigation when the menu is too lengthy

Is there a way to create a dynamic breadcrumbs navigation that adjusts based on the page width, and displays certain elements in a dropdown menu if the navigation becomes too lengthy?

For example, consider the following list:

  <div>
    <nav>
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="#">Home</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials1</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials2</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials3</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials4</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials5</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials6</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials7</a></li>
            <li class="breadcrumb-item"><a href="#">Tutorials8</a></li>
        </ul>
    </nav>
  </div>

This generates the following navigation sequence:

Home > Tutorials1 > Tutorials2 > Tutorials3 > Tutorials4 > Tutorials5 > Tutorials6 > Tutorials7 > Tutorials8

I am looking for a responsive solution to condense long navigations and possibly show items Tutorials2 - Tutorials5 in a dropdown menu like this:

Home > Tutorials1 > ... > Tutorials6 > Tutorials7 > Tutorials8

Any suggestions on how to achieve this?

Answer №1

Take a look at this amazing codepen for some inspiration!

https://codepen.io/ArleyM/pen/pooWyy

HTML

<h1>Responsive breadcrumbs 2014</h1>
<div class="header">Header</div>

<div id="section-title" class="section-title">Expertise</div>

<ol id="sitemap" class="breadcrumb nav">
  <li><a href="#?">Home</a></li>
  <li><a href="#?">About</a></li>
  <li class="active"><a href="#?">Expertise</a>

    <!-- getting into a breadcrumb trail -->
    <ol>
      <li class="active"><a href="#?">Capital Markets</a>

        <ol>
          <li><a href="#?">By the Numbers</a></li>
          <!-- no link on current page -->
          <li class="current">Structured Products</li>
          <li><a href="#?">History</a></li>
        </ol>

      </li>
      <li><a href="#?">Investments</a></li>
    </ol>

  </li><!-- .active -->
  <li><a href="#?">Our Work</a></li>
  <li><a href="#?">Contact</a></li>    
  
</ol><!-- .breadcrumb -->

<h1>Expertise</h1>
<p>Page content! This is an example of a responsive breadcrumb navigation that can also behave as a neat sitemap tool. UX idea by <a href="https://codepen.io/Zinderfine/">@Zinderfine</a>, blogged about <a href="https://arleym.com/codepen-responsive-breadcrumbs/" target="_blank">Here</a></p></p>

<p>This was made in 2014! Updated without floats or jQuery version at <a href="https://codepen.io/ArleyM/pen/RwrKbpM">this link</a>

CSS

@charset "UTF-8";
body {
  padding: 2em;
}

.header {
  background: #eee;
  margin-bottom: 1em;
  padding: 1em 0;
  font-size: 3em;
  color: #bbb;
  text-align: center;
  margin-bottom: 0;
}

ul, ol {
  padding: 0;
}

.nav {
  list-style: none;
  margin-left: 0;
}

.nav > li,
.nav > li > a {
  display: inline-block;
  *display: inline;
  zoom: 1;
}

.breadcrumb ol, .breadcrumb li, .breadcrumb a {
  display: block;
  float: left;
}
.breadcrumb:after {
  content: "";
  display: block;
  clear: both;
}
.breadcrumb li {
  display: inline-block;
}
.breadcrumb a,
.breadcrumb .current {
  padding: .5em;
}
.breadcrumb a {
  text-decoration: none;
}

.section-title {
  display: none;
}

.breadcrumb a:after {
  content: " »";
}

.breadcrumb > li {
  display: none;
}
.breadcrumb > li:first-child, .breadcrumb > li.active, .breadcrumb > li.current {
  display: inline-block;
}
.breadcrumb > li li {
  display: none;
}
.breadcrumb > li li.active, .breadcrumb > li li.current {
  display: inline-block;
}

@media (min-width: 48em) {
  .breadcrumb {
    display: block !important;
  }
}
@media (max-width: 47.938em) {
  .section-title {
    display: block;
    padding: 1em;
    background: #eee;
    cursor: pointer;
    margin-top: 1em;
  }
  .section-title:hover {
    background: #e4e4e4;
  }
  .section-title:before {
    content: "▾ ";
  }
  .section-title.open:before {
    content: "▴ ";
  }

  .breadcrumb {
    padding: 1em;
    margin: 0;
    background: #fcfcfc;
    border: 1px solid #eee;
    border-top: 0;
    display: none;
  }
  .breadcrumb ol, .breadcrumb li, .breadcrumb a {
    float: none;
  }
  .breadcrumb li {
    display: block;
    float: none;
  }
  .breadcrumb a:after {
    content: "";
  }
  .breadcrumb > li:first-child, .breadcrumb > li.active, .breadcrumb > li.current {
    display: block;
  }
  .breadcrumb > li li {
    padding-left: 1em;
  }
}

JS

$('#section-title').on( "click", function() {
  $('#sitemap').slideToggle();
  $(this).toggleClass('open');
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding a command to open a new browser tab using JavaScript code can easily be accomplished by following these steps. By using Terminal, you can quickly and efficiently implement this feature

I'm new to coding and trying to create a terminal simulation. You can check out my code here: https://codepen.io/isdampe/pen/YpgOYr. Command: var coreCmds = { "clear": clear }; Answer (to clear the screen): function clear(argv, argc ...

How do I ensure that my absolutely positioned element is centered in this specific scenario?

I've been working on centering an element within its parent container, and I'm having trouble ensuring it remains centered responsively. Here's what I have so far: HTML <div class="example"> <span class="element1">Element ...

Creating an event listener to conceal a popup with a click

One of the key elements in my project is a popup with the unique identifier of myPopup. The class show is responsible for toggling the display property from none to block, allowing the popup to appear on the screen. As a beginner in using event handlers, ...

Unforeseen rotation happening in CSS animation

I find myself struggling with my math skills from junior high. My goal is to rotate two divs around the Y axis in opposite directions. I have set up two animations for this purpose: @-webkit-keyframes first{ 0% { -webkit-transform: rotateY(0); } ...

Tips on how to update the styling of an active link

http://jsfiddle.net/G8djC/2/ Looking to create a tabbed area where content changes based on the tab clicked. The Javascript function switches the link class to active upon clicking. However, struggling to change the color of the active tab beyond the firs ...

Using Angular ngClass with a conditional statement

Incorporating data from a JSON file instead of a database, my goal is to assign a color to the icon based on the status value in the JSON. For instance, [if green? class1:class2]. Here is the code snippet I am working with: My HTML file <ng-containe ...

Convert an HTML webpage into a JSON format that represents the structure of the DOM tree

I am having an index.html file with multiple div tags inside it. I am attempting to retrieve content from all the div tags on the page, but currently, I am only able to fetch the content from the first div tag. What I actually need is the content from all ...

Comparison of utilizing PHP within CSS versus Implementation through JavaScript [General]

Curious about the incorporation of PHP in CSS, especially in relation to my current Wordpress Theme project. I am aiming for high levels of customization and have been using a JS file to change CSS Properties through PHP. However, I'm not entirely con ...

Using jquery, transform json data into html table format

As a beginner in the realm of coding, I am currently experimenting with extracting data from my json file and transforming it into an HTML table. My tool of choice is the Atom code editor, and I am attempting to use JavaScript, specifically jQuery, to it ...

Identifying elements using xpath - Streamlined Xpath Techniques

I successfully found the element using the xpath copied directly from the code. Can someone assist me in creating a simpler xpath for the following code snippet, which is fully functional! WebElement oCheckbox = myDriver.findElement(By.xpath(".//*[@id=&ap ...

What is the process for including an external .js file in my VueJS2 index.html?

Currently, I am faced with a challenge involving two external Javascript files that are responsible for managing animations and vector triangulation for a background animation. In a typical html/css/js project, adding these two .js files would involve incl ...

What is the best way to set up a webpage so that the left side remains fixed while allowing the right side to scroll?

Currently, I am developing a blog and aiming to position the blog posts on the left side while having the admin panel on the right. Essentially, I want both user and developer interfaces to be fully functional on one page. The developer side should be scro ...

What is the CSS solution for eliminating a line break immediately following the first word?

While designing an email template in html/css for a mailing list, I encountered an issue where on mobile devices the line breaks after the first word for every paragraph. You can see an example of this problem here. The code for the email template was gen ...

What is the process for aligning text with the margin on the left side

Inside a span block, there is an icon: <span><i></i>Text</span> The CSS for the icon is as follows: i { display: inline-block; width: 20px; height: 20px; } When the text inside the span is long, it wraps to the next lin ...

Issues with CSS hovering effects

this is my unique code snippet CSS Stylesheet .Navigation-signIn { background-color: #c8db5a; } .Navigation-signIn։hover { background-color: #ffffff; } JSX Component import { NavLink } from "react-router-dom"; import { BrowserRouter } fro ...

Animations with the -webkit- prefix

I recently came across some CSS code that used the -webkit- prefix inside both @keyframes and @-0webkit-keyframes. This was part of a project called animate.css Do you think this is necessary? ...

Converting HTML to PDF: Transform your web content into

I have a couple of tasks that need to be completed: Firstly, I need to create a functionality where clicking a button will convert an HTML5 page into a .PDF file. Secondly, I am looking to generate another page with a table (Grid) containing data. The gr ...

JavaScript: Retrieving the following element from the parent container

Is there a way to prevent the next element within the parent tag from being enabled or disabled based on a certain condition? HTML: <span> <input type="checkbox" onchange="toggleInput(this)"> </span> <input type="text" ...

What are some techniques for aligning div elements with varying heights?

I have been attempting to align div elements like in this example: https://i.sstatic.net/FoBPg.png However, my result is not turning out as expected: https://codepen.io/online123/pen/VwvGoQP The HTML code I am using is: <div class="under d-flex fle ...

html td elements are breaking due to the application of ngFor

<table> <tr> <th>Date</th> <th>Products</th> </tr> <tr *ngFor="let x of orderdetails"> <td>{{x.orderdate}}</td> <td *ngFor="let y of x.orderproducts"> <span class="break">{{y}}</s ...