0

I want to truncate some long text into a single line in bootstrap 4, I have read many solutions here such as Link 1, Link 2, Link 3 but they were not helpful.

The text I have:

enter image description here

This is how I want it to look:

enter image description here

But this happened with the code as shown below, the table line protrudes outwards a bit, and the text is not in a single line.

enter image description here

Here is my code:

     <div class="row">
            <div class="font-14">
                <table id="userLogTable" class="table table-striped table-bordered" style="width:100%">
                    <thead>
                        <tr>
                            <th class="text-center">#</th>
                            <th class="text-center">LOG LIST</th>
                            <th class="text-center">DETAIL</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>

    columns: [
        { data : "id", "className": "text-center" },
        { data : "log_info", "className": "text-log" },
        { data : "log_id", "className": "text-center",
            render: function(data) {
                return "...";     
            }
        }
    ],

.text-log {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1; /* number of lines to show */
  -webkit-box-orient: vertical;
}
Aditya Prakash
  • 1,549
  • 2
  • 15
  • 31
mastersuse
  • 936
  • 1
  • 15
  • 35

3 Answers3

2

Fix the height of the row and make overflow:scroll. This must work.

ATTR{
  font-size:12px;
  line-height:15px;
  height:30px;
  width:100%;
  overflow:scroll;
  white-space: nowrap;
}

ATTR::-webkit-scrollbar {
    display: none;
}

ATTR {
    -ms-overflow-style: none;
}
hR 312
  • 824
  • 1
  • 9
  • 22
1

Your code is perfect just use

td.text-log {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1; /* number of lines to show */
  -webkit-box-orient: vertical;
}
Mohammed Yousuff
  • 122
  • 1
  • 1
  • 9
0

You simply can use just these lines to truncate the text:

.text-log {
    display: block; //in case if it is not block already 
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}