Using TH colspan to include multiple TD elements per column - html

I'm attempting to create an HTML table that displays a list of vehicles down the page along with columns for each hour of the day. Within each hourly column I would like to display five bars of varying colors that indicate activity over 12 minute periods. This is an abbreviated version of my latest attempt showing the first two hours:
<table>
<thead>
<tr>
<th class="mobile_column" colspan="1">Mobile Name</th>
<th class="time_column" colspan="5">00</th>
<th class="time_column" colspan="5">01</th>
</tr>
</thead>
<tr>
<td class="mobile_column">Test</td>
<td class="no_data"> </td>
<td class="ignition_off"> </td>
<td class="no_data"> </td>
<td class="no_data"> </td>
<td class="no_data"> </td>
<td class="moving"> </td>
<td class="moving"> </td>
<td class="moving"> </td>
<td class="no_data"> </td>
<td class="no_data"> </td>
</tr>
</table>
I'm using the following CSS to format each bar:
.no_data, .no_data_legend {
background-color: White;
}
.moving, .moving_legend {
background-color: Green;
}
.idling, .idling_legend {
background-color: Yellow;
}
.ignition_off, .ignition_off_legend {
background-color: Red;
}
.ignition_toggle, .ignition_toggle_legend {
background-color: Purple;
}
.no_data, .moving, .idling, .ignition_off, .ignition_toggle {
width: 5px;
height: 24px;
float: left;
display: inline-block;
padding: 0px 0px 0px 0px;
}
I'm fairly inexperienced in HTML layout but from my reading I was expecting that five of the bars should appear under each of the hourly headings and go across the page, however they all appear under the first hour and then wrap down the page.
I've posted a JSFiddle at http://jsfiddle.net/dKb6Z/2/ that contains the data for 24 hours that makes it more apparent. Any assistance including preferred alternative ways to format the data would be appreciated.

Remove
float: left;
display: inline-block;
from your CSS. It is destroying the standard table layout.
Working jsFiddle here.

Further to #winterblood's answer (sorry, unable to comment), if you are wanting to remove the padding from the cells (which I am assuming you were trying to do with the float + inline-block), you can add the following:
table {
border-collapse: collapse;
}
th, td {
padding: 0;
}
Fiddle

See this demo mate, I also added a dotted border so that you can see the 5 cells clearly, aligned under each hour. Also changed white color to grey as it's invisible on JS Fiddle default background.
Remember to include this table {border-collapse:collapse;}
Demo here: http://jsfiddle.net/Godinall/Tc2cx/1/

Related

space before a table ONLY IF the table is printed

I'm creating a report card for grades K-6 which prints certain tables based on the student's grade. For example, a 5th grader wouldn't have "Reading Stage" displayed on the report card, but a 1st grader would. I've got the styles formatted correctly to conditionally print the tables, but it's the spacing in between the tables I'm struggling with.
I want there to be a standard amount of space between tables, so I've tried things like adding a blank row as the first row of the table, or adding margin-top=50pt. Everything I've tried results in space added for ALL tables, even the hidden ones, so there is sometimes 200 points of dead space between tables. Not good.
I need a (creative) way to conditionally add space ONLY IF the table is going to be printed.
I'm unsure as to how you're hiding your tables. If you hide them via the HTML5 hidden attribute or display: none, no top margin would interfere with your layout.
If for some reason you can't hide your content in one of these ways, CSS negation could be helpful. In this example, I'm saying that all tables not of a certain class should have margin-top: 1em.
table:not(.skip) {
margin-top: 1em;
}
.skip {
position: relative;
background-color: yellow;
}
.skip::after {
position: absolute;
top: 3px;
left: 150%;
content: ' <-- no margin-top';
white-space: nowrap;
}
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="skip">
<tr>
<td>table</td>
</tr>
</table>
<table>
<tr>
<td>table</td>
</tr>
</table>
<table class="skip">
<tr>
<td>table</td>
</tr>
</table>
<table>
<tr>
<td>table</td>
</tr>
</table>
I know the above has already answered but were you aware of #media print css? You could add some conditional print css that would only be applied when you are printing.
// only for testing, you can print normally without this. It is just for stackoverflow testing...
$("#testPrint").on("click", function() {
window.print();
});
#media print {
/* styles go here */
.myTables {
background: orange !important;
margin: 100px !important;
border: 1px solid black !important;
width: 500px;
}
}
.myTables {
background: pink;
border-collapse: collapse;
border: 1px dashed black;
padding: 5px;
margin: 5px;
text-align: center;
}
<!-- you dont need this javascript either -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<div id="wrapper">
<table class='myTables'>
<tr>
<td>test1</td>
<td>test2</td>
</tr>
</table>
<table class='myTables'>
<tr>
<td>test1</td>
<td>test2</td>
</tr>
</table>
<table class='myTables'>
<tr>
<td>test1</td>
<td>test2</td>
</tr>
</table>
</div>
<button id="testPrint">TEST PRINT</button>

CSS : When to use display flex and display inline-block?

Hi, I have a scenario in which i want to make the above view. I am using Bootstrap4 and I know I can achieve this by using either display:flex or display:inline-block. Now I really wanna know which to use when ? What's the best practice ?
Right now i am doing something like this.
.job-details-container {
display: flex;
}
.job-details-container .job-details-type {
width: 15%
}
<div class="job-details-container">
<div class="job-details-type">Id</div>
<div class="job-details-content">0234</div>
</div>
Well, this is essentially a table. So I suggest using HTML tables. The cells will stretch automatically just like with flex. Tables are fully supported back to IE 8.
.job-details {
border-collapse: collapse;
width: 80%;
margin: auto;
}
td, th {
border-bottom: 1px solid #dddddd;
text-align: left;
padding: 10px;
}
<table class="job-details">
<tr>
<td>Id</td>
<td>0234</td>
</tr>
<tr>
<td>Service Type</td>
<td>Move</td>
</tr>
<tr>
<td>Schedule</td>
<td>11:00 am, Jan 1, 2019</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
</tr>
</table>
Change to flex if you want to create layouts and complex designs. For displaying simple text or maybe some images, tables are your friends.

Several table formatting issues with CSS

I am almost finished with the first outline of my comparison table that I'm trying to create. I have encountered some issues though that I cannot solve. And I've tried different classes, id's and properties, but it either end up doing nothing or changing something that was not intended. Some issues I solved on my own though.
Instead of posting several questions one by one, spamming SO. I put a hold on myself and grouped my questions together. So here it goes:
My Goal:
To the far left, I want to create a column that first is blank and then holds all the titles of each row.
Then I want each row that will contain a product to follow a falling sequence of: 1. Product image
2. company name
3. product name
4. price
5. button
6. HERE IS A WHITE BLANK ROW: With a category title (e.g.Functions or Compability).
7. First title in left td (e.g. audio, video). Then continuing the falling sequence with a check or x-mark in each cell, depending on that product includes named specification (audio..video.. etc)
My problem are these:
How do I get everything centred above each other? Except Left column titles which are supposed to be left-aligned.
How do I make all rows above the Category title-row, without the hover effect?
How to make the "Category Title" to rest on the 2px solid gray border?
How to make all rows above Category Title to become white?
Is there a better way to make this border in a more efficient way?
/* thick border for the top row */
#borderbottom{
border-bottom: 2px solid gray;
}
I figure that i should probably make two separate tables CSS for each table, but when I tried, the two tables did not align with each other.
This is my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Compare Table</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<br/>
<br/>
<table class="hoverTable">
<tr>
<td class="blankcell"></td>
<td>IMAGE</td>
<td>IMAGE</td>
<td>IMAGE</td>
</tr>
<tr>
<td class="blankcell"></td>
<td>Company Name<br/>Product Name</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td class="blankcell"></td>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
</table>
<table class="hoverTable">
<tr id="notop">
<td class="blankcell" id="borderbottom"><h3>Category Title</h3></td>
<td id="borderbottom"></td>
<td id="borderbottom"></td>
<td id="borderbottom"></td>
</tr>
<tr>
<td class="rowTitle" colspan="4">TITLE</td>
</tr>
<tr>
<td class="rowTitle">TITLE</td>
<td id="check">&#x2714</td>
<td>&#x2714</td>
<td>&#x2714</td>
</tr>
<tr>
<td class="rowTitle">TITLE</td>
<td id="x01">&#x2716</td>
<td>&#x2716</td>
<td>&#x2716</td>
</tr>
<tr id="nolast">
<td class="rowTitle">TITLE</td>
<td>&#x2714</td>
<td>&#x2714</td>
<td>&#x2714</td>
</tr>
</table>
</body>
</html>
This is my CSS:
th,td {
padding: 15px;
text-align: center;
}
/* Row coloring */
.hoverTable tr:nth-child(even) {
background-color: #FAFAFA;
}
.hoverTable tr:nth-child(odd) {
background-color:#ffffff;
}
/* Upper left cell*/
.blankcell {
background: none!important;
text-align: left;
}
/*top and bottom border*/
#notop{
border:0px;
}
#nolast{
border-bottom:0px;
}
/* HOVER FUNCTION */
.hoverTable{
width:100%;
border-collapse:collapse;
}
.hoverTable td{
padding:4px;
border: #000000 0px solid;
}
/* Define the default color for all the table rows */
.hoverTable tr{
background: #ffffff;
border-bottom:1px solid #B5B3B3;
border-top:1px solid #B5B3B3;
}
/* Define the hover highlight color for the table row */
.hoverTable tr:not(:nth-child(1)):hover {
background-color: #FFF0E6;
border-left:5px solid #ff6600;
}
/* Check and X-Mark Coloring*/
#check {
color: #1CF200;
}
#x01 {
color: #ff6969;
}
/* Left-hand title */
.rowTitle {
font-weight: bold;
text-align: left;
}
/* thick border for the top row */
#borderbottom{
border-bottom: 2px solid gray;
}
JSFiddle
Thank you for any help provided!
How do I get everything centred above each other? Except Left column titles which are supposed to be left-aligned.
All of the content is already being center. You already have code to left align text. It's being used on the bottom table for the first column.
.rowTitle {
font-weight: bold;
text-align: left !important;
}
How to make the "Category Title" to rest on the 2px solid gray border? Add the class category in the h3 tag
h3.category {
margin-bottom: -8px;
}
How do I make all rows above the Category title-row, without the hover effect?
You can use separate code that just doesn't use the hover code. Basically copy the hovertable with ".hoverTable tr:not(:nth-child(1)):hover" and call the new class something like toptable. (There might be a more efficient way.
How to make all rows above Category Title to become white?
If you use seperate code with basically the same values just don't copy over
.hoverTable tr:nth-child(even) {
background-color: #FAFAFA;
}
.hoverTable tr:nth-child(odd) {
background-color:#ffffff;
}
Is there a better way to make this border in a more efficient way? I would use a tag for Category. The colspan will span the 4 columns below it.
CSS
th {
border-bottom: 2px solid grey;
}
HTML
<thead>
<tr>
<th colspan="4">Category Title</th>
</tr>
</thead>
See some of these applied to this jsfiddle http://jsfiddle.net/x6co362t/
Yes you should make 2 different set of codes as this will solve most of your problems. How do they not align up? Can you should what is supposed to be aligned up?

Overflow:hidden not working in Firefox?

I have a table with rounded corner, and I've put an overflow: hidden CSS command on it so that the corners of the individual cells don't protrude out. It works fine on Chrome, but not on Firefox. Can someone tell me what's wrong?
<style>
table {
border-spacing: 0px;
border: 1px solid #222;
border-radius:8px;-moz-border-radius:8px;-webkit-border-radius:8px;
overflow: hidden;
}
th {
height: 30px;
color: #fff;
background: #222;
text-align: left;
}
tr:nth-child(even) {
background: #245876;
color: #fff;
border: none;
height: 25px;
}
tr:nth-child(odd) {
height: 23px;
}
.pos {
width: 50px;
}
.name {
width: 175px;
}
</style>
<table>
<thead>
<tr>
<th class="pos"></th>
<th class="name">Name</th>
<th class="amount">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td class="pos">1</td>
<td class="name">Bob</td>
<td class="amount">1324353</td>
</tr>
<tr>
<td class="pos">2</td>
<td class="name">John</td>
<td class="amount">10611</td>
</tr>
<tr>
<td class="pos">3</td>
<td class="name">Bill</td>
<td class="amount">3270</td>
</tr>
<tr>
<td class="pos">4</td>
<td class="name">Brian</td>
<td class="amount">1950</td>
</tr>
<tr>
<td class="pos">5</td>
<td class="name">Dan</td>
<td class="amount">1760</td>
</tr>
</tbody>
</table>
The spec does not require the behavior you are looking for: "The ‘border-radius’ properties do apply to ‘table’ and ‘inline-table’ elements. When ‘border-collapse’ is ‘collapse’, the UA may apply the border-radius properties to ‘table’ and ‘inline-table’ elements, but is not required to." (http://dev.w3.org/csswg/css-backgrounds/#border-radius-tables)
It is possible it simply will not work in Firefox. If that's the case, you could apply border-radius to the header cells (:first-child and :last-child in the header row), but it doesn't always line up properly. A bit of a PITA, I know.
thead tr th:first-child { border-radius:8px 0 0 0; }
thead tr th:last-child { border-radius:0 8px 0 0; }
This might help. How to make CSS3 rounded corners hide overflow in Chrome/Opera
Add where you want:
-moz-overflow: hidden;
I like Pete Scott's answer. But depending on your design, you can create the radius effect on a table by wrapping the table itself in a containing element that has the radius left and right, overflow hidden. Then, position relative the table, and -*px to create the required visual effect. But without seeing the desired end result, I am unable to provide an example.
It's possible to change the effect of overflow on the table element with the following trick: change the display of the table, e.g., to inline-block (this value preserves the shrink-fit width of the table and shouldn't break the layout assuming the table is surrounded by block elements). The resulting rendering will be equivalent as if the table has the div wrapper with border-radius and overflow, which renders in Firefox without problems. Here is the JSbin example.

Align 2 divs side by side - right with random width, left using remaining width [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Two divs, one fixed width, the other, the rest
I want 2 divs side by side, where the right has a random width (this contains another 2 divs - a header with a random text and a body with a random image, all generated by JS) while the left should use the remaining width (this also contains another 2 divs - a header and a body, both containing static text only).
I currently have a solution with 3 tables that was quite simple do come up with, but as I'm recoding all my tables without strict tabular contents to CSS (yes I'm quite a few years late with this) I would prefer to have this in CSS too, if it's at all possible? After searching for a solution for quite some time it seems it may not be...
Worth noting is that the image height is always the same, also the width of every image is specified in the JS.
My current solution (with the JS and more stripped out to be as simple and clear as possible, the image is just an example and may have a width of up to 250px): My fiddle
HTML:
<table class="container" cellpadding="0">
<tr>
<td>
<table class="left">
<thead>
<tr>
<th>Text Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>This just contains text.
</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="right">
<thead><tr>
<th>Image Header</th>
</tr></thead>
<tbody>
<tr>
<td>
<img src="http://www.derdiz.com/wp-content/uploads/2011/06/vertigo.jpg" width="200" height="200" border="0" style="display:block;">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
CSS:
table {
border-collapse: collapse;
}
table.container {
width: 500px;
background-color: #DDD;
border: 1px solid #0F0;
}
.container td {
vertical-align: top;
}
table.left {
border: 0px;
}
table.right {
border-left: 1px solid #F00;
}
.left th, .left td, .right th, .right td {
padding: 3px;
}
.left thead th, .right thead th {
background-color: #00F;
color: #FFF;
font-weight: bold;
text-align: left;
}
.right tbody td {
background-color: #888;
}
Please tell if you also want the JS and my unfinished CSS only solution.
Rather than js, if you use two floating divs, one containing the text and text header, one containing the image and image header, I think it should do what you want:
http://jsfiddle.net/PeyWR/10/
(I lost some of your styling, but I think the idea's there).