I am displaying some information in a normal table for desktop viewing. In that table long paragraphs of text wrap perfectly fine. But when it shift to mobile view, where the columns are all stacked the long text overwrites itself.
Normal Table View
Mobile Table View
Here is my html:
<div id="card">
<table class="table">
<thead class="thead-dark">
<tr>
<th>Date</th><th>User</th><th>Description</th><th>Text</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Date">2020-01-23 14:29:14</td><td data-label="User">Lylellen Hederstrom</td>
<td data-label="Desc">Owner Contact Information</td>
<td data-label="Text ">This code is owned by ZP Growers. 3824 Sunset Dr. Fallbrook, CA 92028</td>
</tr>
<tr>
<td data-label="Date">2020-01-28 15:41:26</td><td data-label="User">Lyle Kafader</td>
<td data-label="Desc">ZP Growers Purchase</td>
<td data-label="Text ">October 2014, $2500, TractorsPlus, Phoenix AZ. This is the story of bringing the tractor back to Valley Center. I had to borrow Riley's truck because my little Nissan could not haul a big enough trailer. The trailer that I rented didn't have sway bars which made for a very exciting trip through a windy desert.</td>
</tr>
</tbody>
</table>
</div>
Here is my CSS:
#media screen and (max-width: 760px) {
#card table {
border: 0;
table-layout: fixed;
width: 95%;
}
#card table thead {
display: none;
}
#card table tr {
margin-bottom: 20px;
dispaly: block;
border-bottom: 2px solid #ddd;
box-shadow: 2px 2px 1px #dadada;
height: auto;
}
#card table td {
display: block;
text-align: right;
font-size: 13px;
height: 100%;
width: 100%;
word-wrap: break-word;
}
#card table td::before {
content: attr(data-label);
float: left;
text-transform: uppercase;
font-weight: bold;
}
#card tbody {
line-height:0!important;
}
}
Related
Given a simple table that is a child of an article.
The table has a 100% width so it fits its article parent.
I want the table to expand a little out, side ways both left and right, in a symmetrical way.
In my code the table does expand nicely on the left side, however it does not react to anything I set in CSS on the right side.
(Notice that the left text is nicely aligned with the text that is outside of the table, despite the table having margins set.)
The left side works perfectly, but the right side does not.
What I want to achieve is for the right side of the table to expand in the same way outward and towards the right, a few pixels.
What have I overlooked here? Thanks!
body,
html {
background: #EEE;
margin: 60px;
width: auto
}
article {
background: #DDD;
width: auto
}
table {
border-collapse: collapse;
width: 100%;
border-spacing: 0;
margin: 0 -10px 0 -10px;
/* Expand the Table on both left and right side */
}
th,
td {
padding: .5em 5px;
text-align: left;
border-bottom: 1px solid #ddd;
border-color: black;
border-style: solid;
border-width: 1px;
overflow: hidden;
word-break: normal;
}
table td {}
table th {
font-weight: bold;
}
.today {
background-color: #FFD700
}
tr:hover {
background-color: #FFD700
}
<html>
<body>
<article>
Start<br> Start
<br> Start
<br>
<br>
<table>
<tbody id="weekdagtabel">
<tr id="day-1">
<td>Maandag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-2">
<td>Dinsdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-3">
<td>Woensdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-4">
<td>Donderdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-5">
<td>Vrijdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-6">
<td>Zaterdag</td>
<td>Gesloten.</td>
</tr>
<tr id="day-0">
<td>Zondag</td>
<td>Gesloten.</td>
</tr>
</tbody>
</table>
<br> End
<br> End
<br> End
<br>
</article>
</body>
</html>
You don't actually want the table to be 100% width. You want 100% plus whatever negative margins you add to the parent.
body,
html {
background: #EEE;
margin: 60px;
width: auto
}
article {
background: #DDD;
width: auto
}
table {
border-collapse: collapse;
width: calc(100% + 10px + 10px); /* Add the negative margins from below */
border-spacing: 0;
margin: 0 -10px 0 -10px; /* Expand the Table on both left and right side */
}
th,
td {
padding: .5em 5px;
text-align: left;
border-bottom: 1px solid #ddd;
border-color: black;
border-style: solid;
border-width: 1px;
overflow: hidden;
word-break: normal;
}
table td {}
table th {
font-weight: bold;
}
.today {
background-color: #FFD700
}
tr:hover {
background-color: #FFD700
}
<html>
<body>
<article>
Start<br> Start
<br> Start
<br>
<br>
<table>
<tbody id="weekdagtabel">
<tr id="day-1">
<td>Maandag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-2">
<td>Dinsdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-3">
<td>Woensdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-4">
<td>Donderdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-5">
<td>Vrijdag</td>
<td>08:00 tot 20:00</td>
</tr>
<tr id="day-6">
<td>Zaterdag</td>
<td>Gesloten.</td>
</tr>
<tr id="day-0">
<td>Zondag</td>
<td>Gesloten.</td>
</tr>
</tbody>
</table>
<br> End
<br> End
<br> End
<br>
</article>
</body>
</html>
I am trying to display some text in the bottom left of my table but having some issues getting that. What can I try to get that to display?
.table_b10 {
width: 10cm;
height: 2cm;
border: 1px solid;
margin-left: auto;
margin-right: auto;
}
.heading2_b10 {
font-family: calibri;
font-weight: bold;
font-size: 11;
text-align: center;
}
<table class="table_b10">
<tbody>
<tr>
<td class="heading2_b10">Text</td>
</tr>
<tr>
<td class="heading2_b10">LADIES STOCKINGS SYN-BLACK</td>
</tr>
</tbody>
</table>
I think the simplest thing to do would be just to add style="text-align:left;" to the html tag's attribute
Can colspan attribute help you in this case?
.table_b10 {
width: 10cm;
height: 2cm;
border: 1px solid;
margin-left: auto;
margin-right: auto;
}
heading2_b09 {
font-family:calibri;
font-weight: bold;
font-size: 8;
text-align: center;
}
.heading2_b10 {
font-family:calibri;
font-weight: bold;
font-size: 11;
text-align: center;
}
<table class="table_b10">
<tbody>
<tr>
<td class="heading2_b10" colspan="2">Text</td>
</tr>
<tr>
<td class="heading2_b09">LOG-ID: ###</td>
<td class="heading2_b10">LADIES STOCKINGS SYN-BLACK</td>
</tr>
</tbody>
</table>
Explanation: colspan attribute can be applied on a <td> element, it allows you to set how columns wide the element should be.
What is changed?
The first row has colspan="2", that means his width will be extended to 2 columns, like the one under. But this one has really two columns to show where the LOG-ID: ### string is the first, aligned on the left and LADIES STOCKINGS SYN-BLACK one is the second
I have a table on my html page made by using angular but mainly HTMl & CSS (see the code snippets down below).
Because the tables are probably going to be rather large eventually, we wanted to make the table to be able to scroll. That itself, wasn't that big of a problem, and the table with only one value didn't cause any problems either.
After some fiddeling around the second table that has four values, did not want to work with me.
I have tried various lines of css that also have been used on the other table. It probably is something really simple that I just can't think of right now.
This is the table with only one value, and works just fine.
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Locaties</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let location of locations | filterPipeDep: searchToken">
<td (click)="SpecificLocation(location.departmentId)">{{location.departmentName}}</td>
</tr>
</tbody>
</table>
table {
-webkit-border-radius: 8px !important;
-moz-border-radius: 8px !important;
border-radius: 8px !important;
background-color: rgba(245, 245, 245, 0.644);
color: black;
}
thead {
background-color: rgb(245, 245, 245);
color: black;
}
tbody {
display: block;
overflow-y: auto;
width: 100%;
height: 350px;
}
tr {
display: block;
width: 100%;
}
td, th{
text-align: center;
display: block;
}
The table that doesn't work (and I did see the missing td and th class, but display block on every td and th with multiple rows isn't really a solution)
<table class="table table-striped table-hover">
<thead>
<tr>
<th>E-mail</th>
<th>Voornaam</th>
<th>Achternaam</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let user of users | filterPipeUsers: searchToken">
<td (click)="SpecificUser(user.userId)">{{user.username}}</td>
<td (click)="SpecificUser(user.userId)">{{user.firstName}}</td>
<td (click)="SpecificUser(user.userId)">{{user.lastName}}</td>
<td><a (click)="Debug()"><img class="delete"
src="https://cdn4.iconfinder.com/data/icons/controls-add-on-flat/48/Contols_-_Add_On-35-512.png" /></a>
</td>
</tr>
</tbody>
</table>
table {
-webkit-border-radius: 8px !important;
-moz-border-radius: 8px !important;
border-radius: 8px !important;
background-color: rgba(245, 245, 245, 0.644);
color: black;
}
thead {
background-color: rgb(245, 245, 245);
color: black;
}
tbody {
display: block;
overflow-y: auto;
width: 100%;
height: 350px;
}
tr {
display: block;
width: 100%;
}
Like I said, it probably is something really simple I am just missing or overlooking. What I would like to see is the table being able to scroll down and up, with a fixed header, the text lined out and using 100% of the table with even widths.
*Note, this question has basically been overhauled from a previous version so as to be more precise. Thus some of the answers below do not completely the restructed question.
I have two sets of data which I need to display tabulated. As both sets of data need to have the column widths (but still be dynamic), I am using two <tbody>'s.
I am trying to set a heading for each of the tabulated data, in a way that the heading takes up the width of the entire <tbody>.
I have tried using table-caption, but it does not apply to the tbody, but the table itself. Meaning all captions look to go to the top of the table, regardless of where they are in the html.
To demonstrate what I am running into, see the following snippet:
table {
width: 100%;
border-collapse: collapse;
color: black;
margin-bottom: 2px;
}
tbody:before {
display: table-caption;
font-size: 1.25em;
padding: 16px;
background-color: #303030;
font-weight: bold;
color: white;
width: 100%;
}
#tbody1:before {
content: 'tbody1';
}
#tbody2:before {
content: 'tbody2';
}
th,
td {
padding: 4px 0px;
border: 1px solid black;
}
caption {
border: 1px dotted black;
}
<table>
<tbody id="tbody1">
<caption>Caption1</caption>
<tr>
<th>bob</th>
<th>dob</th>
</tr>
</tbody>
<tbody id="tbody2">
<caption>Caption2</caption>
<tr>
<th>dob</th>
<th>bob</th>
</tr>
</tbody>
</table>
My current attempt is to use :before. But as you can see, the :before does not take up the entire width of the tbody. Even with width: 100% it does not work.
Another way I realized it could be done is to have another row for each tbody, and set colspan to equal the amount of columns for that table. Like this:
table {
width: 100%;
border-collapse: collapse;
color: black;
margin-bottom: 2px;
}
th,
td {
padding: 4px 0px;
border: 1px solid black;
}
caption {
border: 1px dotted black;
}
<table>
<tbody id="tbody1">
<tr>
<th colspan="2">Title1</th>
</tr>
<tr>
<th>bob</th>
<th>dob</th>
</tr>
</tbody>
<tbody id="tbody2">
<tr>
<th colspan="2">Title2</th>
</tr>
<tr>
<th>dob</th>
<th>bob</th>
</tr>
</tbody>
</table>
However, the only problem there is that it does not become dynamic and requires you to know how many columns there will be ahead of time. Normally this would not be a problem but I am looking for a more dynamic solution in my case.
My question is: How does one add a caption to a tbody (not the table) in a way so that each caption relates to the applicable tbody and not the table
You just need to set the width to 100vw. This sets the width to 100% of the viewport width. For a more in-depth explanation of viewport width, see this article.
table {
width: 100%;
border-collapse: collapse;
color: black;
margin-bottom: 2px;
}
#tbody1:before, #tbody2:before {
display: table-caption;
font-size: 1.25em;
padding: 16px;
background-color: #303030;
font-weight: bold;
color: white;
width: 100vw;
}
#tbody1:before {
content: 'tbody1';
}
#tbody2:before {
content: 'tbody2';
}
th, td {
padding: 4px 0px;
border: 1px solid black;
}
<table>
<tbody id="tbody1">
<tr>
<th>bob</th>
</tr>
</tbody>
<tbody id="tbody2">
<tr>
<th>dob</th>
</tr>
</tbody>
</table>
I need help with a responsive table. What's needed is to basically have it change to a 'mobile version' upon resizing, however the mobile version is a little different to the main style of it, as the image shows.
I've currently got this: http://jsfiddle.net/MLsZ8/
HTML:
<table class="crafting">
<thead>
<tr>
<th style="width:15%">Name</th>
<th style="width:20%">Ingredients</th>
<th style="width:205px;">Input > Output</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ore Blocks</td>
<td>Gold Ingots, Iron Ingots, Diamonds and Lapis Lazuli Dye</td>
<td><img width="204" height="112" title="Crafting Ore Blocks" src="http://www.minecraftxl.com/images/crafting/Crafting-Ore-Blocks1.gif" alt="Crafting Ore Blocs from Ingots" /></td>
<td>Turn ingots or diamonds into a placeable block. Can be used for storage or to show off.</td>
</tr>
</tbody>
</table>
CSS:
td {
border:0;
}
table.crafting {
border-spacing:0;
border-collapse:collapse;
}
.crafting th {
border:2px solid #f3f3f3;
padding:5px;
}
.crafting td {
border:2px solid #f3f3f3;
padding:5px;
vertical-align:top;
}
.crafting tr {
background:#c6c6c6;
}
.crafting-name {
font-weight:bold;
border-bottom:0 !important;
background:#c6c6c6;
}
.crafting-ingredients {
border-top:0 !important;
border-bottom:0 !important;
background:#bcbcbc;
}
.crafting-img {
width:205px;
border-bottom:0 !important;
border-top:0 !important;
background:#c6c6c6;
}
.crafting-desc {
border-top:0 !important;
background:#bcbcbc;
}
If you are not opposed to changing the overall format of the HTML, I have a solution that might be a bit easier to handle...
If you change the current table structure to a series of div elements, you can nest each table row into a container div.
I'll give you an example for one "row":
<div class="tableRow">
<div class="columnOne"> content </div>
<div class="columnTwo"> content </div>
<div class="columnThree"> content </div>
<div class="columnFour"> content </div>
</div>
Then, using CSS, you could set .tableRow {width: 100%}. From here, you could set the column widths based on your needs. From your example, it looks like you could do:
.columnOne {width: 10%; float: left;}
.columnTwo {width: 15%; float: left;}
.columnThree {width: 30%; float: left;}
.columnFour {width: 45%; float: left;}
Then, when you reach your mobile view breakpoint, using a #media query, you can do the following:
.columnOne, .columnTwo, .columnThree, .columnFour {width: 100%}
This will cause the columns to effectively become rows of width: 100%.
Option 1:
Full tables
http://jsfiddle.net/2655u/
Option 2
Convert tables to div in used mediaqueries
HTML
<div class="title">
<div class="name">Name</div>
<div class="ingredients">Ingredients</div>
<div class="field">Input > Output</div>
<div class="description">Description</div>
</div>
<div class="responsive">
<div class="name">Ore Blocks</div>
<div class="ingredients">Gold Ingots, Iron Ingots, Diamonds and Lapis Lazuli Dye</div>
<div class="field">
<img width="204" height="112" title="Crafting Ore Blocks" src="http://www.minecraftxl.com/images/crafting/Crafting-Ore-Blocks1.gif" alt="Crafting Ore Blocs from Ingots" />
</div>
<div class="description">Turn ingots or diamonds into a placeable block. Can be used for storage or to show off.</div>
</div>
CSS
div {
display: table;
width: 100%;
table-layout: fixed;
}
div > div {
display: table-cell;
background : #C6C6C6;
border:2px solid #f3f3f3;
padding:5px;
vertical-align : top;
}
div.title {
text-align : center;
font-weight:bold;
}
div.name {
width : 90px;
}
div.ingredients {
width : 150px;
}
div.field {
width : 205px;
}
#media only screen and (max-width: 767px) {
.title {display:none;}
.responsive div {
display : block;
width : auto;
text-align : center;
background : white;
}
.responsive div.ingredients {background : #C6C6C6;}
.responsive div.description {background : #C6C6C6;}
}
Example: http://jsfiddle.net/2DTSG/
Well, I was also searching for the same one day. Got the following. It follows the same approach, converting columns to rows when getting viewed in smaller device.
http://css-tricks.com/responsive-data-tables/
Before moving ahead see the Live Demo
One simple solution is to have two tables: a regular table (with class full) and a mobile one (with class mobile). Then you can use a media query to switch between them at a particular screen size.
If your website isn't particularly heavy, this is an approach that will save a lot of headache.
Example fiddle: http://jsfiddle.net/QDrPb/
.mobile {
display:none;
}
#media (max-width:767px) {
.full {
display:none;
}
.mobile {
display:block;
}
}
Twitter Bootstrap is a nice thing to achieve table-responsiveness.
http://getbootstrap.com/
You have to download it from the above link and add the css file.
After that, apply like this: http://getbootstrap.com/css/#tables-responsive
I hope this may help your need.
Thanks
here simple demo please reffer this link for pure css demo fiddle
/*by Ñ££¿ Upadhyay*/
body {
font-family: "Open Sans", sans-serif;
line-height: 1.25;
}
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;a
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 18px;
margin: 10px;
}
table tr {
background: #f8f8f8;
border: 1px solid #ddd;
padding: 10px;
}
table th,
table td {
padding: 10px;
text-align: center;
}
table th {
font-size: 14px;
letter-spacing: 0;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 14px;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: 5px;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: 14px;
text-align: right;
}
table td:before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
padding-right: 70px;
}
table td:last-child {
border-bottom: 0;
}
}
<table>
<caption>Statement Summary</caption>
<thead>
<tr>
<th scope="col">Account</th>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Visa - 6076</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Corporate AMEX</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Acount">Visa - 3412</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
</tbody>
</table>
Responsive Tables JavaScript Plugin
<link rel="stylesheet" href=".../dist/css/table-fluid.css"/>
<script src=".../dist/js/table-fluid.js"></script>
<table class="table-fluid">
<thead>
...
</thead>
<tbody>
...
</tbody>
</table>
Use JavaScript function
window.tableFluid('.table-fluid');
https://www.npmjs.com/package/table-fluid
https://github.com/maestro888/table-fluid
Table cells cannot rearrange they way you want - rows and columns are locked and cannot float. All you can do is change the layout WITHIN each cell. You will need to change your mark-up completely to make that happen.