How to create a table with divs and different column width? - html

I have a table created only with divs with fixed width columns. But I need to change width of columns with bootstrap or any other way.
Html:
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead">Title1 </div>
<div class="rTableHead">Title2 </div>
<div class="rTableHead">Title3 </div>
<div class="rTableHead">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
</div>
</div>
</div>
</div>
</div>
Styles:
.rTable {
display: block;
width: 100%;
border: 1px solid #ddd;
}
.rTableHeading, .rTableBody, .rTableFoot, .rTableRow {
clear: both;
}
.rTableHead, .rTableFoot {
background-color: #FBFBFB;
font-weight: bold;
width: 100%;
padding: 0 !important;
}
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
width: 24%;
}
.rTableCell {
height: 46px;
}
.rTable:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
When I need 4 columns I should use width=24% for all columns. But how can I create columns with different width? Is there a way to use bootstrap column classes to do this?

You need to put your table in correctly first. Then you can resize columns as you want. I have recreated your table in html, and applied the css style to it to change the width of each column.
You should look at nth-child and nth-of-type in W3Schools sometime. Thery're very helpful.
thead th:nth-child(1) {
background: red;
width: 10%;
}
thead th:nth-child(2) {
background: pink;
width: 20%;
}
thead th:nth-child(3) {
background: purple;
width: 5%;
}
thead th:nth-child(4) {
background: green;
width: 50%;
}
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<table class="table table-striped table-hover table-condensed table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title3</th>
<th>Title4</th>
</tr>
</thead>
<tbody>
<tr>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td>row1</td>
</tr>
<tr>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td>row2</td>
</tr>
</tbody>
</table>
</div>
</div>

Yes there is, try this. If I understand the question correctly that is. I'm not 100% sure where you want to actually add the width, but I would assume this would do what you are asking for.
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead col-sm-3">Title1 </div>
<div class="rTableHead col-sm-3">Title2 </div>
<div class="rTableHead col-sm-3">Title3 </div>
<div class="rTableHead col-sm-3">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
</div>
</div>
</div>
</div>
</div>
Also, I would take out the width% in your CSS for rTableCell if you are utilizing the bootstrap column sizing. You can still add sizing here if you would like to see how it impacts your columns. It isn't right or wrong, but first see what it looks like without the width% and then come back to add width to your liking.
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
/* width: 24%; */
}

Maybe there is a better solution with bootstrap but I used this approach for now.
.rTableHeading .rTableHead:nth-child(1) ,
.rTableBody .rTableCell:nth-child(1) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(2) ,
.rTableBody .rTableCell:nth-child(2) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(3) ,
.rTableBody .rTableCell:nth-child(3) {
width: 15%;
}
.rTableHeading .rTableHead:nth-child(4) ,
.rTableBody .rTableCell:nth-child(4) {
width: 20%;
}
I also cleared width=24% from rTableCell and rTableHead.

Related

Table height 100% difference between Firefox and Chrome

I've a table inside another table in HTML/CSS - and I want the inside table be at height 100% of the surrounding table cell.
Something like that (the pink table has 100% of the height):
That works fine in Firefox - but in Chrome I get this:
The code for both is:
.largeNumber {
font-size: 10.5em;
line-height: 1;
}
.table-base {
display: table;
border-collapse: collapse;
width: auto !important;
margin: 0 auto;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
<div class="table-base" style="border: 1px solid black;">
<div class="table-row">
<div class="table-cell">
<span class="largeNumber">cell1 in t1</span>
</div>
<div class="table-cell" style="vertical-align: middle;height: 100%; border: 2px dashed green;">
<div class="table-base" style="border: 3px solid pink; height: 100%;">
<div class="table-row">
<div class="table-cell"><span style="color:red">cell1 in t2</span>
</div>
</div>
<div class="table-row">
<div class="table-cell"><span style="color:blue">cell2 in t2</span>
</div>
</div>
</div>
</div>
</div>
</div>
I tried to keep it simple.
But who gets it wrong? FF or Chrome? And how can I talk Chrome into drawing the inside table 100% in height?
So, you want the table with class table-base to have 100% the height of the other table, that's right?
If so, I defined the height to 100% on that class.
.largeNumber {
font-size: 10.5em;
line-height: 1;
}
.table-base {
display: table;
border-collapse: collapse;
width: auto !important;
margin: 0 auto;
height: 100%;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
}
<div class="table-base" style="border: 1px solid black;">
<div class="table-row">
<div class="table-cell">
<span class="largeNumber">cell1 in t1</span>
</div>
<div class="table-cell" style="vertical-align: middle;height: 100%; border: 2px dashed green;">
<div class="table-base" style="border: 3px solid pink; height: 100%;">
<div class="table-row">
<div class="table-cell"><span style="color:red">cell1 in t2</span>
</div>
</div>
<div class="table-row">
<div class="table-cell"><span style="color:blue">cell2 in t2</span>
</div>
</div>
</div>
</div>
</div>
</div>
Hope this helps.
Regards

Div overflow does not align correct

How can I make the second line be one line and not broken up as it is now?
And look like this:
I tried to use the display: table and table-cell but it makes no difference.
I never seem to get along with CSS.
css:
<style>
.column1 {
float: left;
width: 10%;
font-size: 350%;
}
.column2 {
float: left;
width: 10%;
font-size: 350%;
}
.column3 {
float: left;
width: 80%;
font-size: 350%;
}
</style>
html:
<div class="row" style="display: table">
<div class="column1" style="background-color:#ccc;" display: table-cell;>
<b>col1</b><br>
<div style="background-color:#FF0000;">32</div>
<div style="background-color:#00FF00;">33</div>
</div>
<div class="column2" style="background-color:#ccc;" display: table-cell;>
<b>col2</b><br>
<div style="background-color:#FF0000;">11:00</div>
<div style="background-color:#00FF00;">12:00</div>
</div>
<div class="column3" style="background-color:#ccc;" display: table-cell;>
<b>col3</b><br>
<div style="background-color:#FF0000;">This is some text That will overflow the div by a few words</div>
<div style="background-color:#00FF00;">Next line</div>
</div>
If you want to use "table CSS" you might aswell adjust the markup. I made an example here
Demo here
table {
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid black;
text-align: left;
padding: 8px;
}
th {
background-color: white;
}
tr:nth-child(odd) {
background-color: #00FF00;
}
tr:nth-child(even) {
background-color: #FF0000;
}
<table>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
<tr>
<td>31</td>
<td>11:00</td>
<td>This is some text That will overflow the div by a few words</td>
</tr>
<tr>
<td>32</td>
<td>12:00</td>
<td>Next line</td>
</tr>
</table>
This is how I was able to achieve it. To achieve word wrap properly, we need to use display:table-row as well
CSS:
.column1 {
float: left;
width: 10%;
font-size: 350%; //100%
}
.column2 {
float: left;
width: 10%;
font-size: 350%; //100%
}
.column3 {
float: left;
width: 80%;
font-size: 350%; //100%
}
.row1 {
background-color:#ccc;
display: table-row;
}
.row2 {
display: table-row;
background-color:#FF0000;
}
.row3 {
display: table-row;
background-color:#00FF00;
}
HTML
<div style= "display: table;">
<div class= "row1">
<div class= "column1" style= "display:table-cell"><b>col1</b></div>
<div class= "column2" style= "display:table-cell"><b>col2</b></div>
<div class= "column3" style= "display:table-cell"><b>col3</b></div>
</div>
<div class= "row2">
<div class= "column1" style="display:table-cell">32</div>
<div class= "column2" style= "display:table-cell">11:00</div>
<div class= "column3" style= "display:table-cell">This is some text That will overflow the div by a few words</div>
</div>
<div class= "row3">
<div class= "column1" style= "display:table-cell">33</div>
<div class= "column2" style= "display:table-cell">12:00</div>
<div class= "column3" style="display:table-cell">Next line</div>
</div>
Demo Link: http://jsfiddle.net/5qc7adf9/1/show/
It will display properly only in full screen result window as font size is 350% here. To view it properly in result window of jsfiddle, we would need to reduce font-size.

Make column height same

I need your help on this. I would like to make the filter section the same as the result section. However, I am having a hard time on how to make it the same as in the results. I've also been reading the article on Equal Height Columns with Cross-Browser CSS
Below are the codes which I've done. Note that the height is dependent on the results pane or on the filters pane.
#SearchAll tr td {
vertical-align: top;
}
#SearchAllPane {
background: grey;
}
#container1 {
float: left;
border: 1px solid;
}
#container2 {
float: left;
}
#col1 {
float: left;
width: 160px;
background: white;
padding-left: 10px;
height: calc(100% - 54px);
}
#col2 {
float: left;
width: 20px;
/*background: grey;*/
}
#col2 img {
width: 18px;
height: 18px;
}
.FilterItem {
height: 30px;
line-height: 30px;
}
#ResultTable {
width: 300px;
border: 1px solid;
}
.ResultRow {
height: 30px;
line-height: 30px;
background-color: green;
font-size: 15px;
}
<table id="SearchAll">
<tr>
<td id="SearchAllPane">
<div id="container2">
<div id="container1">
<div id="col1">
<div class="FilterItem">
Filter 1
</div>
<div class="FilterItem">
Filter 1
</div>
<div class="FilterItem">
Filter 1
</div>
</div>
<div id="col2">
<img src="http://uxrepo.com/static/icon-sets/font-awesome/svg/angle-left.svg" />
</div>
</div>
</div>
</td>
<td>
<table id="ResultTable">
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
<tr>
<td class="ResultRow">Results</td>
</tr>
</table>
</td>
</tr>
</table>
Here's the link of what I've done: http://jsfiddle.net/arw5n4qb/
Your markup is pretty complicated, which is going to make styling it harder; here's a simple version. (Run the snippet below, or see this jsfiddle.) The important part is: one div contains the left side content, one contains the right side, and both of those are set to display: table-cell. Their parent container is set to display: table;. Sibling elements set to display: table-cell will automatically sit next to each other without wrapping. They'll also match their heights, so both will be as tall as the tallest content.
If you want the filters and rows to be vertically centered with each other, you can add vertical-align: middle to those sibling divs or to their parent. Otherwise, as you can see, they default to aligning their content along the top.
.container {
display: table; /* important */
border: 1px solid gray;
}
.filters,
.results {
display: table-cell; /* also important */
width: 200px;
}
.filters {
background: white;
}
/* the rest is cosmetic -
* change these styles if needed */
.filter, .result {
line-height: 2;
padding: 0 10px;
}
.result {
background: green;
color: white;
border: 1px solid white;
}
<div class="container">
<div class="filters">
<div class="filter">Filter 1</div>
<div class="filter">Filter 2</div>
<div class="filter">Filter 3</div>
</div>
<div class="results">
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
<div class="result">Result row</div>
</div>
</div>

Setting the variable percentage width of HTML elements next to other variable-width elements

I have a HTML structure with given CSS.
Both caption and progress elements should be rendered in same line. caption elements should not have fixed width and progress elements should fill up the rest of the space next to caption based on their inline-set width, which means that every progress element will have a different total pixel-width but should fill up only the given percentage of available space.
HTML structure and CSS rules can be changed in any way.
Is it possible to solve this problem with CSS only?
.table {
padding: 15px;
width: 280px;
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
}
.caption {
float: left;
}
.progress {
height: 14px;
border: 1px solid white;
border-radius: 4px;
background-color: green;
overflow: hidden;
}
.value {
margin-left: 5px;
}
<div class="table">
<div class="row">
<div class="caption">Short text: </div>
<div class="progress" style="width:11.65%">
<span class="value">11.65</span>
</div>
</div>
<div class="row">
<div class="caption">A bit longer text: </div>
<div class="progress" style="width:100%">
<span class="value">100.00</span>
</div>
</div>
<div class="row">
<div class="caption">X: </div>
<div class="progress" style="width:45.50%">
<span class="value">45.50</span>
</div>
</div>
</div>
Have you considered using Flexbox?
Just add this rule:
.row {
display: flex;
}
If your are concerned about browser support, an alternative would be using display:table. You should change your markup and CSS, like this:
.table {
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
padding: 15px;
width: 280px;
}
.inner-table {
display: table;
}
.row {
display: table-row;
}
.caption {
display: table-cell;
white-space: nowrap;
width: 1%;
}
.progress {
background-color: green;
border: 1px solid white;
border-radius: 4px;
display: table-cell;
height: 14px;
}
.value {
margin-left: 5px;
display:block;
width:0;
overflow: visible;
}
<div class="table">
<div class="inner-table">
<div class="row">
<div class="caption">Short text: </div>
<div style="width:1.65%" class="progress">
<span class="value">1.65</span>
</div>
<div class="remainder"></div>
</div>
</div>
<div class="inner-table">
<div class="row">
<div class="caption">A bit longer text: </div>
<div style="width:100%" class="progress">
<span class="value">100.00</span>
</div>
<div class="remainder"></div>
</div>
</div>
<div class="inner-table">
<div class="row">
<div class="caption">X: </div>
<div class="progress" style="width:45.50%">
<span class="value">45.50</span>
</div>
<div class="remainder"></div>
</div>
</div>
</div>
Please try this - padding-right: 5px; display:inline; add these properties in progress class and also remove width in progress.
Well, just for the future reference, I was playing a bit with the flexbox thingie and came up with this:
.table {
padding: 15px;
width: 280px;
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
}
.row {
display: flex;
}
.caption {
margin: 1px 5px 1px 0;
}
.progress {
flex-grow: 1;
margin: auto;
}
.progress-content {
height: 14px;
border-radius: 4px;
background-color: green;
}
.value {
margin-left: 5px;
}
<div class="table">
<div class="row">
<div class="caption">Short text:</div>
<div class="progress">
<div class="progress-content" style="width:11.65%">
<span class="value">11.65</span>
</div>
</div>
</div>
<div class="row">
<div class="caption">A bit longer text:</div>
<div class="progress">
<div class="progress-content" style="width:100%">
<span class="value">100.00</span>
</div>
</div>
</div>
<div class="row">
<div class="caption">X:</div>
<div class="progress">
<div class="progress-content" style="width:45.50%">
<span class="value">45.50</span>
</div>
</div>
</div>
</div>
If I get a solution without flexbox, will accept it as an answer :)

Colspan/Rowspan for elements whose display is set to table-cell

I have the following code:
.table {
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
}
.colspan2 {
/* What to do here? */
}
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
<div class="row">
<div class="cell colspan2">Cell</div>
</div>
</div>
Pretty straightforward. How do I add a colspan (or the equivalent of colspan) for elements with display: table-cell?
As far as I know, the lack of colspan/rowspan is just one of the limitations of display:table. See this post:
http://www.onenaught.com/posts/201/use-css-displaytable-for-layout
Since OP does not explicitly rule that solution must be pure CSS, I'll be stubborn and throw in my workaround I figured out today, especially since it's much more elegant than having a table inside a table.
Example equals to <table> with two cells per row and two rows, where the cell in the second row is a td with colspan="2".
I have tested this with Iceweasel 20, Firefox 23 and IE 10.
div.table {
display: table;
width: 100px;
background-color: lightblue;
border-collapse: collapse;
border: 1px solid red;
}
div.row {
display: table-row;
}
div.cell {
display: table-cell;
border: 1px solid red;
}
div.colspan,
div.colspan+div.cell {
border: 0;
}
div.colspan>div {
width: 1px;
}
div.colspan>div>div {
position: relative;
width: 99px;
overflow: hidden;
}
<div class="table">
<div class="row">
<div class="cell">cell 1</div>
<div class="cell">cell 2</div>
</div>
<div class="row">
<div class="cell colspan">
<div><div>
cell 3
</div></div>
</div>
<div class="cell"></div>
</div>
</div>
Live action (demo) here.
EDIT:
I finetuned the code to be more printer-friendly, as they leave background-colors out by default. I also created rowspan-demo, inspired by late answer here.
A simpler solution that works for me in Chrome 30 :
Colspan can be emulated by using display: table instead of display: table-row for the rows :
.table {
display: block;
}
.row {
display: table;
width: 100%;
}
.cell {
display: table-cell;
}
.row.colspan2 {/* You'll have to add the 'colspan2' class to the row, and remove the unused <div class=cell> inside it */
display: block;
}
The only pitfall is that the cells of stacked rows won't align vertically, as they're from different tables.
If you're looking for a straight CSS way to simulate a colspan, you could use display: table-caption.
.table {
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
border: 1px solid #000;
}
.colspan2 {
/* What to do here? */
display: table-caption;
}
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
<div class="row">
<div class="cell colspan2">Cell</div>
</div>
</div>
Simply use a table.
table's are only frowned upon when being used for layout purposes.
This seems like tabular data (rows/columns of data). Therefore I would recommend using a table.
See my answer to this question for more information:
creating the same thing with divs as tables
Here's one way to span columns in CSS I used for my own situation.
https://jsfiddle.net/mb8npttu/
.table {
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
border: 1px dotted red;
}
.colspan {
max-width: 1px;
overflow: visible;
}
<div class='table'>
<div class='row'>
<div class='cell colspan'>
spanning
</div>
<div class='cell'></div>
<div class='cell'></div>
</div>
<div class='row'>
<div class='cell'>1</div>
<div class='cell'>2</div>
<div class='cell'>3</div>
</div>
</div>
There is a solution to make the colspan the widht of the entire table. You can not use this technique to colspan a part of the table.
Code:
* {
box-sizing: border-box;
}
.table {
display: table;
position: relative;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
border: 1px solid red;
padding: 5px;
text-align: center;
}
.colspan {
position: absolute;
left: 0;
width: 100%;
}
.dummycell {
border-color: transparent;
}
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
<div class="row">
<div class="cell dummycell"> </div>
<div class="cell colspan">Cell</div>
</div>
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
</div>
Explanation:
We use position absolute on the colspan to make it the full width of the table. The table itself needs position relative. We make use of a dummycell to maintain the height of the rows, position absolute does not follow the flow of the document.
Of course you can also use flexbox and grid to tackle this problem these days.
CSS
.tablewrapper {
position: relative;
}
.table {
display: table;
position: relative
}
.row {
display: table-row;
}
.cell {
border: 1px solid red;
display: table-cell;
}
.cell.empty
{
border: none;
width: 100px;
}
.cell.rowspanned {
position: absolute;
top: 0;
bottom: 0;
width: 100px;
}
.cell.colspan {
position: absolute;
left: 0;
right: 0;
}
HTML
<div class="tablewrapper">
<div class="table">
<div class="row">
<div class="cell rowspanned">
Center
</div>
<div class="cell">
Top right
</div>
</div>
<div class="row">
<div class="cell empty"></div>
<div class="cell colspan">
Bottom right
</div>
</div>
</div>
</div>
Code
It can be done just with pure CSS and centering the text across the "fake" colspan.
The trick is to set the rows to position:relative, then to place "empty divs" in the row where you want to make the colspan (they must have height in order to work), set the cell where the content is in as display:grid, and finally, applying position:absolute to the element inside the cell (and center it as you may center any other absolute element).
.table {
display: table;
}
.row {
display: table-row;
position: relative;
}
.cell {
display: table-cell;
background-color: blue;
color: white;
height: 26px;
padding: 0 8px;
}
.colspan2 {
display: grid;
}
.colspan2 p {
position:absolute;
left: 50%;
transform:translateX(-50%);
margin: 0;
}
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
<div class="row">
<div class="cell colspan2"><p>Cell</p></div>
<div class="cell"></div>
</div>
</div>
By using the appropriate div classes and CSS attributes, you can mimic the desired effects of the colspan and rowspan.
Here's the CSS
.table {
display:table;
}
.row {
display:table-row;
}
.cell {
display:table-cell;
padding: 5px;
vertical-align: middle;
}
Here's the sample HTML
<div class="table">
<div class="row">
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">X</div>
<div class="cell">Y</div>
<div class="cell">Z</div>
</div>
<div class="row">
<div class="cell">2</div>
<div class="cell">4</div>
<div class="cell">6</div>
</div>
</div>
</div>
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">A</div>
</div>
<div class="row">
<div class="cell">B</div>
</div>
</div>
</div>
<div class="cell">
ROW SPAN
</div>
</div>
</div>
</div>
</div>
</div>
From what I'm seeing in both the questions, and most responses, is people seem to forget that in any given div that's acting as a "table-cell" you can insert another div that's acting like an embedded table, and start the process over.
***It's not glamorous, but it does work for those looking for this type of formatting and they want to avoid the TABLEs. If its for DATA LAYOUT, TABLEs do still work in HTML5.
Hopefully, this will help someone.
You can set the position of colspan content as "relative" and the row as "absolute" like this:
.table {
display: table;
}
.row {
display: table-row;
position: relative;
}
.cell {
display: table-cell;
}
.colspan2 {
position: absolute;
width: 100%;
}
You can't achieve this at present.
AFAIK this would be covered by CSS Tables, a specification which appears to currently be at "work in progress" state.
You can try this solution, where you can find how to apply colspan using div
https://codepen.io/pkachhia/pen/JyWMxY
HTML:
<div class="div_format">
<div class="divTable">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell cell_lable">Project Name</div>
<div class="divTableCell cell_value">: Testing Project</div>
<div class="divTableCell cell_lable">Project Type</div>
<div class="divTableCell cell_value">: Web application</div>
</div>
<div class="divTableRow">
<div class="divTableCell cell_lable">Version</div>
<div class="divTableCell cell_value">: 1.0.0</div>
<div class="divTableCell cell_lable">Start Time</div>
<div class="divTableCell cell_value">: 2016-07-10 11:00:21</div>
</div>
<div class="divTableRow">
<div class="divTableCell cell_lable">Document Version</div>
<div class="divTableCell cell_value">: 2.0.0</div>
<div class="divTableCell cell_lable">End Time</div>
<div class="divTableCell cell_value">: 2017-07-10 11:00:23</div>
</div>
<div class="divTableRow">
<div class="divTableCell cell_lable">Document Revision</div>
<div class="divTableCell cell_value">: 3</div>
<div class="divTableCell cell_lable">Overall Result</div>
<div class="divTableCell cell_value txt_bold txt_success">: Passed</div>
</div>
</div>
<div class="divCaptionRow">
<div class="divCaptionlabel">Description</div>
<div class="divCaptionValue">: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore</div>
</div>
</div>
</div>
CSS:
body {
font-family: arial
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box
}
.div_format {
width: 100%;
display: inline-block;
position: relative
}
.divTable {
display: table;
width: 100%;
}
.divTableRow {
display: table-row
}
.divTableHeading {
background-color: #EEE;
display: table-header-group
}
.divTableCell,
.divTableHead {
display: table-cell;
padding: 10px
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
font-weight: bold
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold
}
.divTableBody {
display: table-row-group
}
.divCaptionRow{
display: table-caption;
caption-side: bottom;
width: 100%;
}
.divCaptionlabel{
caption-side: bottom;
display: inline-block;
background: #ccc;
padding: 10px;
width: 15.6%;
margin-left: 10px;
color: #727272;
}
.divCaptionValue{
float: right;
width: 83%;
padding: 10px 1px;
border-bottom: 1px solid #dddddd;
border-right: 10px solid #fff;
color: #5f5f5f;
text-align: left;
}
.cell_lable {
background: #d0d0d0;
border-bottom: 1px solid #ffffff;
border-left: 10px solid #ffffff;
border-right: 10px solid #fff;
width: 15%;
color: #727272;
}
.cell_value {
border-bottom: 1px solid #dddddd;
width: 30%;
border-right: 10px solid #fff;
color: #5f5f5f;
}
Use nested tables to nest column spans...
<div class="table">
<div class="row">
<div class="cell">
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="cell">Cell</div>
</div>
</div>
Or use 2 tables where the column span covers the whole row...
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
</div>
<div class="table">
<div class="row">
<div class="cell">Cell</div>
</div>
</div>
Even if this is an old question, I would like to share my solution to this problem.
<div class="table">
<div class="row">
<div class="cell">Cell</div>
<div class="cell">Cell</div>
</div>
<div class="row">
<div class="cell colspan">
<div class="spanned-content">Cell</div>
</div>
</div>
</div>
<style>
.table {
display: table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
}
.colspan:after {
/* What to do here? */
content: "c";
display: inline;
visibility: hidden;
}
.spanned-content {
position: absolute;
}
</style>
Here is a fiddle.
It's not really a span, and the solution is a bit hacky, but it is usefull in some situations. Tested on Chrome 46, Firefox 31 and IE 11.
In my case, I had to present some non-tabular data in a tabular way, keeping the width of the columns and giving title to sub-sections of the data.