I am trying to display various items in tabular format (each entry has various attributes). The following is also required:
display: table/table-row/table-cell
instead of <table>/<tr>/<td>
- as per example code). (Another reason for me is that I use JSF, which generates HTML, but sort of leaves me stuck with with using this.)text-overflow: ellipsis
on this summary, together with other needed settings. Because the surrounding <div>
already has display: table-cell
, while the ellipsis
attribute needs an inline/block element, the "summary" text is wrapped in another <div>
.Here is an example of the desired effect (note NO scrollbar at bottom):
While this is what I am currently able to achieve (NOT ideal) (note scrollbar at bottom - which indicates table runs off window on right):
Here is barebones code to achieve this (one could omit all attributes marked with /*l&f*/
(look and feel), they are only meant to generate a cleaner-looking, easier to debug example).
CSS and HTML:
A {
/*l&f*/text-decoration: inherit;
/*l&f*/color: inherit;
}
.list-table {
display: table;
/*l&f*/border: 1px solid blue;
/*l&f*/border-spacing: 5px;
}
.list-tr {
display: table-row;
/*l&f*/background-color: lightgray;
}
.list-td {
display: table-cell;
white-space: nowrap; /* one line */
/*l&f*/padding: 2px; border : 1px solid green;
/*l&f*/border: 1px solid red;
}
.summary {
display: block;
white-space: nowrap; /* one line */
overflow: hidden; /* make text overflow */
text-overflow: ellipsis; /* truncate tex with ... */
/*l&f*/background-color: lightblue;
}
<div class="list-table">
<a href="#1" class="list-tr">
<div class="list-td">Row 1</div>
<div class="list-td">More stuff</div>
<div class="list-td">
<div class="summary">Some single line run on text goes here</div>
</div>
</a>
<a href="#2" class="list-tr">
<div class="list-td">Row 2</div>
<div class="list-td">Other column</div>
<div class="list-td">
<div class="summary">This is text content that runs on and on
and on without end and may need to be truncated somewhere on the
summary screen depending on screen size to show only the first part
that will fit.</div>
</div>
</a>
<a href="#3" class="list-tr">
<div class="list-td">Row 3</div>
<div class="list-td">Still other content</div>
<div class="list-td">
<div class="summary">Here is still more long text that may
need truncation in the summary version because it is so long.</div>
</div>
</a>
</div>
I have been able to achieve the desired result with display: -moz-box
(and various other -moz-
settings), in the summary
style. Not happy because this is not cross-platform.
Do you have any better suggestions? Your help is much appreciated :-)
If you can make changes to your exported HTML then you have here a possible solution.
I made a few changes to your HTML (added a parent div to .summary
, to create a fixed table by using table-layout:fixed
)
See SNIPPET below:
A {
/*l&f*/
text-decoration: inherit;
/*l&f*/
color: inherit;
}
.list-table {
display: table;
/*l&f*/
border: 1px solid blue;
/*l&f*/
border-spacing: 5px;
width: 100%; /* ADDED */
}
/* CREATED */
.fixed-table {
width:100%;
table-layout: fixed;
display:table
}
.list-tr {
display: table-row;
/*l&f*/
background-color: lightgray;
}
.list-td {
display: table-cell; /* CHANGED */
white-space: nowrap;
/* one line */
/*l&f*/
padding: 2px;
border: 1px solid green;
/*l&f*/
border: 1px solid red;
}
.summary {
display: table-cell;
/*l&f*/
background-color: lightblue;
white-space: nowrap;
/* one line */
overflow: hidden;
/* make text overflow */
text-overflow: ellipsis;
/* truncate texT with ... */
}
<div class="list-table">
<a href="#1" class="list-tr">
<div class="list-td">Row 1</div>
<div class="list-td">More stuff</div>
<div class="list-td">
<div class="fixed-table">
<div class="summary">Some single line run on text goes here</div>
</div>
</div>
</a>
<a href="#2" class="list-tr">
<div class="list-td">Row 2</div>
<div class="list-td">Other column</div>
<div class="list-td">
<div class="fixed-table">
<div class="summary">This is text content that runs on and on and on without end and may need to be truncated somewhere on the summary screen depending on screen size to show only the first part that will fit.</div>
</div>
</div>
</a>
<a href="#3" class="list-tr">
<div class="list-td">Row 3</div>
<div class="list-td">Still other content</div>
<div class="list-td">
<div class="fixed-table">
<div class="summary">Here is still more long text that may need truncation in the summary version because it is so long.</div>
</div>
</div>
</a>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With