I've been struggling for hours to implement text truncation in a flexbox layout (mainly with Bootstrap 5) but have had no success. I've come across suggestions to use min-with: 0
on the parent div, but despite trying various combinations, I can't seem to make it work.
I've also read about align-items-center
causing text stretching and the need for width: 100%
, but that hasn't resolved the issue for me either.
The code snippet provided aims to illustrate the problem, please disregard any layout inconsistencies.
Can anyone offer guidance in the right direction?
Thank you
Edit: I am attempting to avoid explicitly defining the width as it needs to remain responsive
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddbfb2b2a9aea9afbcad9de8f3ecf3ee">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ae8e5e5fef9fef8ebfacabfa4bba4b9">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="list-group">
<li class="list-group-item list-group-item-secondary">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" aria-label="Search" aria-describedby="userManagmentSearch" />
<span class="input-group-text" id="userManagmentSearch">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
</svg>
</span>
</div>
</li>
<li class="list-group-item">
<div class="d-flex justify-content-between">
<div class="d-flex">
<img style="width: 24px" class="me-3" src="https://via.placeholder.com/24x24.png" alt="User Avatar" />
<div class="d-flex align-items-center">
<div>
<span class="fw-bold">admin</span>
<br />
<span class="text-muted text-truncate">
admin@email.comaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</span>
</div>
</div>
</div>
<div class="d-flex justify-content-end align-items-center flex-wrap">
<span class="badge bg-danger mx-1 my-1">Admin</span>
<span class="badge bg-success mx-1 my-1">Moderator</span>
<span class="badge bg-secondary mx-1 my-1">User</span>
</div>
</div>
</li>
<li class="list-group-item">moderator</li>
<li class="list-group-item">moderatoranduser</li>
</ul>;