'Navbar dropdown overflows because there's a lot of text
Let's say that I have the following navbar:
I'm not very familiar with bootstrap nor with styling, and I'm trying to fix the overflow of the navbar. I tried floating, positioning, and more, but I guess it doesn't work that way when this is a full bootstrap navbar(?).
The ideal solution would be that if the text is overflowing, it should go to the next line. Is there a way to fix this?
Code
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown" *ngIf="authService.loggedIn()">
<a class="nav-link dropdown-toggle" routerLink="/profile" routerLinkActive="active" ´ id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Profile (Dropdown)
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" routerLink="/balance">Menu too long to fit in this because there is way to much text</a>
<a class="dropdown-item" routerLink="/cuenta-perdidas-ganancias">Menu too long to fit in this place</a>
<a class="dropdown-item" routerLink="/route">Menu</a>
<a class="dropdown-item" routerLink="/">Menu</a>
<a class="dropdown-item" routerLink="/route">Menu</a>
<div class="dropdown-divider"></div>
</div>
</li>
</ul>
</nav>
Solution 1:[1]
You need to manage with CSS the behavior of the overflowing text.
Try add the following style to your code:
a.dropdown-item {
inline-size: 250px;
overflow-wrap: break-word;
white-space: normal;
}
Fiddle: https://jsfiddle.net/kongallis/n02ha5ds/20
For more info: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Text/Wrapping_Text
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Konstantinos Gallis |

