text-overflow: ellepsis not working - html

I have this table that I want to spruce up a bit, but am having no succes despite the solutions I have found all across Stackoverflow.
I am using PHP to echo the table, with some some data from an SQL db.
As you can see in the bottom right, the browser does not see the styling I have added for overflow etc..
Below is the html:
<div class="span9">
<div class="container">
<a class="btn" href="records.php">Add New Record</a><br><br>
<table class="table table-hover table-condensed" border="1" cellpadding="10">
<tbody>
<tr>
<th class="th.id">ID</th>
<th class="th.status">Status</th>
<th class="th.cust">Customer</th>
<th class="th.prod">Product</th>
<th class="th.ord">Order Number</th>
<th class="th.ret">Return Code</th>
<th class="th.dop">Date of Purchase</th>
<th class="th.sn">Serial Number</th>
<th class="th.prob">Problem Description</th>
<th class="th.rep">Repair Description</th>
<th class="th.part">Parts Used</th>
<th class="th.com">Comments</th>
</tr>
<tr>
<td><p>1</p></td>
<td><p>Error!</p></td>
<td><p>Jesse</p></td>
<td><p>Fuse</p></td>
<td><p></p></td>
<td><p></p></td>
<td><p></p></td>
<td><p>ComicalCanary</p></td>
<td><p>Not enough sand</p></td>
<td><p>Added sand</p></td>
<td><p>sand 10kg</p></td>
<td><p>I want to put a lot of content into this, to see how far this will go in stretching the table.</p></td>
</tr>
</tbody>
</table>
</div>
And below is my css, i'm using Bootstrap 3.3.7, but this is what I'm adding:
.table {
width: 100%;
max-width: 100%;
margin-bottom: 20px;
table-layout: fixed;
}
.table td {
width: 120px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
And even the width: 120px; is not even working...
Any clues anyone?

You have to move your ellipsis styling down to the p tag.
.table p {
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
https://jsfiddle.net/koralarts/y6q3uvkL/1/

Set the max-width on your td css or put a div inside the td with the ellipsis on the div instead. Or set the p width to a fixed number and put the text overflow rule on that.
Table cells are a bit difficult in this regard, text overflow works with block elements (p, div, etc) in the inline direction. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow

Move both overflow: hidden; and text-overflow: ellipsis; from .table td to a new rule for .table td p, like
.table td {
width: 120px;
white-space: nowrap;
}
.table td p {
overflow: hidden;
text-overflow: ellipsis;
}
Here's the whole thing in a codepen: https://codepen.io/anon/pen/dJPgNZ

Related

how to prevent table from exceeding the viewport - react bootstrap

I'm working on a react js project again after awhile. I need to show a table that won't exceed the viewport when the content has a very long string.
I tried the solution in this answer successfully on jsfiddle like in this code:
<div className="simple-table">
<Table striped bordered hover>
<thead>
<tr>
<th>Nama Barang</th>
<th>Jumlah</th>
<th>Harga</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lolipop Strawberry</td>
<td>20</td>
<td>Rp 5.000</td>
<td>Rp 100.000</td>
</tr>
</tbody>
</Table>
</div>
.simple-table {
width: 100%;
display: flex;
flex-direction: column;
}
.simple-table table {
width: 100%;
table-layout: fixed; /* add table layout fixed */
overflow: hidden; /* add overflow hidden */
border-collapse: collapse;
}
.simple-table > table td,
.simple-table > table th {
word-wrap: break-word !important;
}
the result on jsfiddle:
but when I try to apply the same code on my react js project, the result is like this:
what am I doing wrong? any help is appreciated.
On jsfiddle word-wrap: break-word is applied, in your project - for some reason - not. You have to check why. Try to debug the application and look if the css rule is applied or not.
it turns out I just needed to add a white-space:normal rule
.simple-table > Table th,
.simple-table > Table td {
white-space:normal !important; /* added this */
word-wrap: break-word !important;
}

HTML display only few text in a single line

Hi I want to display only few text in a html column and remaining to expand only if it is expanded by the user.
All in a single line how do I do it.(as shown in below screenshot)
Below is my code
<table style="border-style: solid;
white-space: pre;
overflow: hidden;
word-wrap: break-word
text-overflow: ellipsis;
border-color: 000708; background-color: 000708;" border="3">
<tbody>
<tr bgcolor="#18C1C1">
<td style="text-align: center; width: 107.588px;"><strong> Tree</strong></td>
<td style="text-align: center; width: 84.275px;"><strong> ID</strong></td>
<td style="text-align: center; width: 81.975px;"><strong> S</strong></td>
<td style="text-align: center; width: 3899.98px;"><strong>Text</strong></td>
<td style="text-align: center; width: 158.688px;"><strong> Name</strong></td>
</tr>
<tr>
<td style="width: 107.588px;">113</td>
<td style="width: 84.275px;">113</td>
<td style="width: 81.975px;">0</td>
<td style="width: 3899.98px;">This s a test and this should not expand after a fixed length --?></td>
<td style="width:
158.688px;">Test</td>
</tr>
</tbody>
</table>
If you don't mind using jQuery then you can give jQuery Resizable a try. jQuery UI Resizeable will allow resizing the element by the user and the CSS will help to hide the text properties rather than moving to the next line.
I also added a unique ID property to the table, keep that in mind if you have multiple tables and act accordingly.
Note: Table headers are draggable here.
$("#myTable thead th").resizable({
handles: "e" //To specify where the drag handles will be placed on the resizable element.
});
table {
table-layout: fixed;
width: 100%;
white-space: nowrap;
overflow: hidden;
}
table th {
white-space: nowrap;
overflow: hidden;
}
table td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<table id="myTable" style="border-style: solid;
overflow: hidden;
word-wrap: break-word
text-overflow: ellipsis;
border-color: 000708; background-color: 000708;" border="3">
<thead>
<tr bgcolor="#18C1C1">
<th ><strong> Tree</strong></th>
<th ><strong> ID</strong></th>
<th ><strong> S</strong></th>
<th ><strong>Text</strong></th>
<th ><strong> Name</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td >113</td>
<td >113</td>
<td >0</td>
<td >This s a test and this should not expand after a fixed length --?></td>
<td >Test</td>
</tr>
</tbody>
</table>
Check out text-overflow property
td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 200px;
}

Dynamic columns fixed length with auto scroll

I am using angular js 1.3 here. What I have is a modal up which when clicked adds an column to existing table, the name of the column is based upon the selection made in the modal. One can add as many columns here. All this works fine. What my issue is that I am not sure how to maintain fixed column width and scrolling.
The width of the column keeps decreasing when more columns are added and even the scrolling does not comes out properly.
Sorry the code is a lot so just posting some code together with jsfiddle here:
http://jsfiddle.net/aman1981/u1vbeos5/107/
<div class="panel-body">
<table class="table table-bordered">
<colgroup>
<col class="unique-id">
</colgroup>
<thead>
<tr>
<th class="unique-id">Name #</th>
<th contenteditable="true" ng-repeat="c in targetTable.columns" ng-model="c.label"></th>
<!--<th class="view-next-set">...</th>-->
<td class="center add-column"><a href ng-click="open()">+ Add Column</a></td>
</tr>
</thead>
<tbody>
<tr ng-repeat="r in targetTable.rows">
<td contenteditable="true" class=""></td>
<td contenteditable="true" ng-repeat="column in targetTable.columns" ng-model="r[column.id]" ng-blur="!r.id? addNewRow(r[column.id], r): undefined"></td>
<!--<td class="blank" colspan="2"></td>-->
</tr>
</tbody>
</table>
</div>
Also here is the image:
https://imgur.com/a/qCn1AO7
So you can set a minimum width fot your .table td and .table th
.table td,
.table th {
min-width: 120px;
}
And you can set the overflow of you .panel-body as auto:
.panel-body {
overflow: auto;
}
http://jsfiddle.net/u1vbeos5/116/
You have to set min-width and max-width to th and oveflow: auto to .panel-body....
Check below CSS
.table th {
max-width: 120px;
min-width: 120px;
}
.panel-body{
overflow: auto;
}
What I end up doing was to add the below classes to TD and Panel:
.fixed-width {
min-width: 50px !important;
width: 50px !important;
}
.panel-body {
overflow: auto;
}

Can't enable ellipse character on long text not fitting the cell in a table

I want an ellipsis to appear whenever the text gets cut off when the width of the table cell is too narrow to display it. According to CSS Tricks, it's supposed to look as below (nothing surprising there).
td {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
However, I can't make it work. First I thought it was because I'm applying Bootstrap and there might be some styling poofing my approach but then I tried to reproduce the error in an isolated fiddle and - tada! - I got it working. (I.e. I got it to fail ellipting, hence got the reproducible error to succeed occurring.)
The fiddle is here. What am I missing?!
Solution 1
Table cells don't handle overflow well. You will need to set the max-width CSS property on each td for the overflow to work. Try to make use of max-width instead of width
The max-width CSS property sets the maximum width of an element.
It prevents the used value of the width property from becoming larger
than the value specified by max-width.
body {
font: 13px Verdana;
}
td {
background-color: pink;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 50px;
}
<table class="table">
<thead>
<th>Name</th>
<th>Alias</th>
<th>Location</th>
<th>Updated</th>
<th>Actions</th>
</thead>
<tbody>
<tr>
<td>Ali Baba & Co.</td>
<td>Boys 'n da hood</td>
<td>Somewhere over the rainbow</td>
<td>February 30th</td>
<td>Do stuff!</td>
</tr>
</tbody>
</table>
Solution 2
Or Just place the td content inside <span> and then apply the css
body {
font: 13px Verdana;
}
span {
background-color: pink;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
display: block;
}
.table {
width: 100%;
table-layout:fixed;
}
<table class="table">
<thead>
<th>Name</th>
<th>Alias</th>
<th>Location</th>
<th>Updated</th>
<th>Actions</th>
</thead>
<tbody>
<tr>
<td><span>Ali Baba & Co.</span></td>
<td><span>Boys 'n da hood</span></td>
<td><span>Somewhere over the rainbow</span></td>
<td><span>February 30th</span></td>
<td><span>Do stuff!</span></td>
</tr>
</tbody>
</table>

th and td width not working

I'm putting together a table where I want the first element of the row if the text is too long should be shortened. For that I use
#name{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}
I have this table and just want "me" you can use the abbreviation text should be very long
#name{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}
<table style="width:100%">
<thead>
<tr>
<th id="name" style="width:20%">Test name test name test name</th>
<th id="number">547821365</th>
<th id="address">test #10900</th>
</tr>
</thead>
</table>
But this does not work, always the first element is enlarged depending on the text and interrupts my other columns.
You can add float:left to your name css class. Here is my fiddle- https://jsfiddle.net/rahulpandey034/oxxnpuo2/
#name{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
float: left;
}
<table style="width:100%">
<thead>
<tr>
<th id="name" style="width:20%">Test name test name test name</th>
<th id="number">547821365</th>
<th id="address">test #10900</th>
</tr>
</thead>
</table>