Я пытаюсь понять, как содержать строку в столбце сетки, когда содержимое очень велико. Рассматриваемая строка состоит из URL-адреса, который может быть довольно длинным.
У меня есть два столбца в сетке начальной загрузки. Если строка в таблице левого столбца очень длинная, правый столбец сжимается. А если левый столбец очень большой, то столбцы сетки располагаются горизонтально, а рассматриваемая длинная строка выходит за границы сайта.
Есть ли способ содержать такие длинные строки? Я попробовал подход, описанный в https://stackoverflow.com/a/18498071, но это не дало никакого эффекта.
Вот мой код. Я использую шаблоны jinja для заполнения второго столбца некоторыми фиктивными данными:
<div class = "container">
<div class = "col">
<h6 class = "text-center">HEADING</h6>
<div class = "form-row">
<div class = "col">
<ul class = "list-group list-group-horizontal">
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
</ul>
</div>
</div>
<br>
<div class = "row">
<div class = "col">
<table class = "table table-stripped table-sm">
<thead>
<tr>
<th scope = "col">Colums</th>
<th scope = "col">Column2</th>
</tr>
</thead>
<tbody>
<tr>
<td>http://amazon.com</td>
<td>75</td>
</tr>
<tr>
<td>www.website.com/somedomain</td>
<td>90</td>
</tr>
<tr>
<td>www.anotherwebsite.comttttttttttttttttttttt0000000000000000000000000000000000000000000000000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt</td>
<td>98</td>
</tr>
</tbody>
</table>
</div>
<div class = "col">
<table class = "table table-stripped table-sm">
<thead>
<tr>
<th scope = "col">Some URLs</th>
</tr>
</thead>
{% for data in dummy_data %}
<tbody>
<tr>
<td>{{data}}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
Вы можете использовать многоточие и максимальную ширину, чтобы содержать длинные элементы данных. Многоточие
<!-- you can use max-width and ellipsis to contain your long data elements-->
<style>
.col1-width {
max-width: 400px;
}
.col2-width {
width: 50px;
text-align: center;
}
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<div class = "container">
<div class = "col">
<h6 class = "text-center">HEADING</h6>
<div class = "form-row">
<div class = "col">
<ul class = "list-group list-group-horizontal">
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
<li class = "list-group-item flex-fill">TEXT</li>
</ul>
</div>
</div>
<br>
<div class = "row">
<div class = "col">
<table class = "table table-stripped table-sm">
<thead>
<tr>
<th scope = "col">Colums</th>
<th scope = "col">Column2</th>
</tr>
</thead>
<tbody style = "width:500px;">
<tr>
<td class = "
ellipsis
col1-width">http://amazon.com</td>
<td class = "col2-width">75</td>
</tr>
<tr>
<td class = "ellipsis col1-width">www.website.com/somedomain</td>
<td class = "col2-width">90</td>
</tr>
<tr>
<td
class = "ellipsis col1-width"
title = "www.anotherwebsite.comttttttttttttttttttttt0000000000000000000000000000000000000000000000000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt"
>
<!-- ellipsis each first td to truncate the data -->
www.anotherwebsite.comttttttttttttttttttttt0000000000000000000000000000000000000000000000000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
</td>
<td class = "col2-width">98</td>
</tr>
</tbody>
</table>
</div>
<div class = "col">
<table class = "table table-stripped table-sm">
<thead>
<tr>
<th scope = "col">Some URLs</th>
</tr>
</thead>
{% for data in dummy_data %}
<tbody>
<tr>
<td>{{data}}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
</div>
</div>
</div>
Не используйте таблицу для стилизации. Используйте таблицы только для отображения данных. Таким образом, ваша проблема не в том, что у вас больше текста, а в том, что вы использовали неправильные инструменты. Для табличного макета без ограничений таблицы используйте CSS-Grid.