Is there a way to create the menu below using Bootstrap 4 so that the icon on the right always stays visible, while the text is automatically truncated with an ellipsis (...) when it overflows?
<li class="nav-item dropdown">
<a href='#' class='a nav-link dropdown-toggle' aria-expanded='false' data-toggle='dropdown'>Dropdown</a>
<ul class='dropdown-menu' role='menu'>
<li><a href="page1.html" class='dropdown-item' role='menuitem'>Long title</a></li>
<li><a href="page2.html" class='dropdown-item' role='menuitem'>Cut off with</a></li>
</ul>
</li>
I've tried displaying the icon using pseudo-element ::after
, but that doesn't allow for applying ellipsis to the text. I also attempted using two DIVs with float-left
and float-right
, but that resulted in overlap issues.
I'm seeking a solution that avoids fixed widths. It seems like using CSS3 flexbox could be the right approach:
<li>
<a href="page1.html" class='dropdown-item' role='menuitem'>
<span class='title'>Long title</span>
<span class='icon'><i class='fa fa-lock'></i></span>
</a>
</li>
Accompanied by the following CSS:
.dropdown-item {display:flex; flex-direction:row}
.title {display:flex; margin-right: auto}
.icon {display: flex}
Unfortunately, this method doesn't seem to work as expected.