Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent new-line in Bootstrap4-apha6 breadcrumb

When the text in the breadcrumbs in Bootstrap4-aplha6 is too long the las crumb will jump to the next line:

<nav class="breadcrumb">
  <a class="breadcrumb-item" href="#">Home</a>
  <a class="breadcrumb-item" href="#">Library</a>
  <a class="breadcrumb-item" href="#">Data</a>
  <span class="breadcrumb-item active">A slightly too long title</span>
</nav>

Produces:

 ---------------------------------
|                                 |
| Home / Library / Data           |
|   / A slightly too long title   |
|                                 |
|                                 |
|                                 |
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

And I would like:

 ---------------------------------
|                                 |
| Home / Library / Data / A slig… |
|                                 |
|                                 |
|                                 |
 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I have tried fixing this with white-space: nowrap, overflow: hidden and text-overflow: ellipsis and it does not seem to work well because, for some reason, in Bootstrap4, the breadcrumb-items are blocks floated left.

Did anyone find the way to fix this without overwriting all the Bootstrap classes (the ellipsis is not 100% necessary)?

like image 428
Daniel Avatar asked Feb 15 '17 01:02

Daniel


People also ask

How do I change breadcrumb separator in bootstrap?

They can be changed by modifying a local CSS custom property --bs-breadcrumb-divider , or through the $breadcrumb-divider Sass variable — and $breadcrumb-divider-flipped for its RTL counterpart, if needed. We default to our Sass variable, which is set as a fallback to the custom property.

Why do we use breadcrumb in bootstrap?

Indicate the current page's location within a navigational hierarchy that automatically adds separators via CSS.

How do I make breadcrumbs in bootstrap 4?

Generally, you will use <nav>, <ol> and <li> tags of HTML for creating breadcrumbs.

What is bread crumbs in HTML?

A breadcrumb navigation provide links back to each previous page the user navigated through, and shows the user's current location in a website.


1 Answers

Michael's solution seems no longer work with Bootstrap 4.1 when using the official breadcrumb snippet (with <ol> and <li> tags). Here is another solution.

.breadcrumb {
    display: block !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.breadcrumb .breadcrumb-item {
    display: inline;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>

    <div class="container">             
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="#">Home</a></li>
                <li class="breadcrumb-item"><a href="#">My category</a></li>
                <li class="breadcrumb-item"><a href="#">My category</a></li>
                <li class="breadcrumb-item"><a href="#">My category</a></li>
                <li class="breadcrumb-item"><a href="#">My category</a></li>
                <li class="breadcrumb-item"><a href="#">My category</a></li>
                <li class="breadcrumb-item active" aria-current="page">My page</li>       
            </ol>
        </nav>        
    </div>
like image 116
David Avatar answered Oct 09 '22 01:10

David