I'm not using the tag, so I can't use the colspan attribute.
I'd like to create a table with three cells in the first row, one cell in the last row and two cells in the other rows.
Here's my code (minimal):
.row {
display: table-row;
}
.cell {
display: table-cell;
}
HTML:
<div style="display: table;">
<div class="row" style="width: 100%;">
<div class="cell" style="width: 33% !important;">
aaaa
</div>
<div class="cell" style="width: 33% !important;">
bbbbb
</div>
<div class="cell" style="width: 33% !important;">
ccccc
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 50% !important;">
ddddd
</div>
<div class="cell" style="width: 50% !important;">
eeeee
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 50% !important;">
fffff
</div>
<div class="cell" style="width: 50% !important;">
ggggg
</div>
</div>
<div class="row" style="width: 100%;">
<div class="cell" style="width: 100% !important;">
last cell
</div>
</div>
</div>
And this is what I get (I can't post images): http://gyazo.com/cc036ed406f6c1a166955522d40e05b0.png
I would build this layout as follows.
For the HTML:
<div class="parent">
<div class="row r3">
<div class="cell">aaaa</div>
<div class="cell">bbbbb</div>
<div class="cell">ccccc</div>
</div>
<div class="row r2">
<div class="cell">ddddd</div>
<div class="cell">eeeee</div>
</div>
<div class="row r2">
<div class="cell">fffff</div>
<div class="cell">ggggg</div>
</div>
<div class="row r1">
<div class="cell">last cell</div>
</div>
</div>
and apply the following CSS:
.row {
display: table;
border: 1px dashed blue;
width: 100%
}
.cell {
display: table-cell;
border: 1px dotted blue;
}
.r3 .cell {
width: 33.333333%;
}
.r2 .cell {
width: 50%;
}
.r1 .cell {
width: 100%;
}
Use display: table for each div.row block element with 100% width.
You don't need to explicitly define a CSS table row, one will be created anonymously as needed.
See reference: http://www.w3.org/TR/CSS2/tables.html#anonymous-boxes
See demo: http://jsfiddle.net/audetwebdesign/72yb5th2/
You're trying to emulate a table with divs. Why? The <table> tag is made for exactly this kind of tabular data.
Related
[enter image description here][1]currently i am facing one problem.
I generated table using div with fix header and scrollbar to div row section.
but problem is both div are not taking whole 50% 50% width.
I have tried following code.but not working.
.brd2 {
height: auto;
max-height: 100px;
overflow: auto;
position: absolute;
width: 100%;
}
.back-clr {
background-color: red;
}
HTML PART
<div class="container">
<div class="row">
<div class="col-md-8">
<div style="display: table;width:100%">
<div style="display: table-row">
<div style="width:50%; display: table-cell;">
Test
</div>
<div style="width:50%; display: table-cell;">
test
</div>
</div>
<div class="brd2" style="display: table-row;">
<div class="content" style="width:50%; display: table-cell;">
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
<p>sdfds
fdsf</p>
<p>dsfds
fds</p>
<p> fds
fsf
dsf</p>
</div>
<div class="content back-clr" style="width:50%;display: table-cell;">
this is second div
</div>
</div>
</div>
</div>
</div>
</div>
For some reason the cells in my second row in my table are changing the width of the cells in the row above. I have no idea why this is the cause. I don't want the width of the first cell in the first row to be changed. I have reproduced the problem in jsfiddle to make it clear what I mean.
FiddleJS link:
https://jsfiddle.net/bpyrgsvc/1/
HTML:
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
<div class="row">
<div class="cell">this changes the width of the cell above</div>
</div>
</div>
CSS:
.table {
display:table;
}
.row {
display: table-row;
}
.cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
}
With CSS you can build a table using a table element and then style how you want using display: block and inline-block. Though if your need really is as simple as it appears to be then a simple colspan will do the jobs.
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
</table>
Appending table within the cell should clarify your issue. Refer the snippet below
.table {
display:table;
table-layout: fixed;
width: 100%;
border-collapse:collapse
}
.row {
display: table-row;
}
.cell.p0{
padding:0;
border:none
}
.cell {
display: table-cell;
padding: 5px;
border: 1px solid black;
}
.cell-full {
// full width of table
}
<div class="table">
<div class="row">
<div class="cell p0">
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="cell cell-full">this changes the width of the cell above</div>
</div>
</div>
I don't see anything wrong with the results. In a div set to be displayed as table and table-row, it is behaving as tables.
To get the result you want, close the first table and start another.
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
</div>
<div class="table">
<div class="row">
<div class="cell cell-full">this changes the width of the cell above</div>
</div>
</div>
https://jsfiddle.net/bpyrgsvc/4/
Flexbox can do that:
.row {
display: flex;
}
.cell {
flex: 1;
padding: 5px;
border: 1px solid black;
}
<div class="table">
<div class="row">
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
<div class="cell">test</div>
</div>
<div class="row">
<div class="cell">this NO LONGER changes the width of the cell above</div>
</div>
</div>
Another way is to set no wrap for whitespaces in css.
<div class="no-wrap-cell">This goes in a single line</div>
.no-wrap-cell{
white-space: nowrap !important;
}
I have the following HTML:
<article id="articlesss" class="container_12 clearfix" style="margin-top: 2em; display: table;">
<div style="display: table-row">
<div class="grid_6" style="display: table-cell;">
<div class="block-border">
<div style="background-color: red; height: 100px;"></div>
</div>
</div>
<div class="grid_6" style="display: table-cell;">
<div class="block-border">
<div style="background-color: red; height: 200px;"></div>
</div>
</div>
</div>
</article>
I am using display: table-row because I heard that this would make my DIVs work like table cells and I was wanting the DIVs to be the same height. However it seems like the first grid_6 grid has a small height while the second has at least 100px. How can I make it fill to be the same height?
Here's an example: fiddle
<div class="block-border">
<div style="background-color: red; height: 100px;"></div>
You have set the height of second element i.e Height = 100px .
Set the height to both the div elements .
Both grid_6 elements are the same height. The reason why you see one red rectangle larger than the other is you are coloring the inside divs. If you put the color on the grid_6 elements - they are the same. http://jsfiddle.net/A7yXc/
<article id="articlesss" class="container_12 clearfix" style="margin-top: 2em; display: table;">
<div style="display: table-row">
<div class="grid_6" style="display: table-cell; background-color: red;">
<div class="block-border">
<div style="height: 100px;">das</div>
</div>
</div>
<div class="grid_6" style="display: table-cell; background-color: red;">
<div class="block-border">
<div style="height: 200px;">das</div>
</div>
</div>
</div>
How to create table layout in HTML only by using by passing both width & height parameters as percentages, not pixels so that it works as the same in all the browsers ?Also pls suggest some good material or link where I can find the format for required attributes & their values used to accomplish this task.Early replies are appreciated.
Check this http://jsfiddle.net/nalaka526/hUFh4/6/
CSS
.divTable
{
width: 50%;
height: 50%;
display: table;
}
.divTableRow
{
width: 100%;
height: 100%;
display: table-row;
}
.divTableCell
{
width: 25%;
height: 100%;
display: table-cell;
}
HTML
<div class="divTable">
<div class="divTableRow">
<div class="divTableCell">
H1
</div>
<div class="divTableCell ">
H2
</div>
<div class="divTableCell ">
H3
</div>
<div class="divTableCell ">
H4
</div>
</div>
<div class="divTableRow">
<div class="divTableCell">
a
</div>
<div class="divTableCell ">
b
</div>
<div class="divTableCell ">
c
</div>
<div class="divTableCell ">
d
</div>
</div>
</div>
I'm not entirely sure what you're asking. Do you just want a fluid <table> layout? Below is a very basic example of a fluid layout. Keep in mind, the table will only be as wide as the container it's in.
<table width="100%" height="100%">
<tr width="25%" height="100%">
<td></td>
</tr>
<tr width="75%" height="100%">
<td></td>
</tr>
</table>
Only in IE does this not work, it displays the cells stacked vertically on top one another? Is there anyway to fix this so that IE7 will display it like a table?
<div class="table" style="width: 1100px; margin-top: 5px;";>
<div class="tr header">
<div class="td" style="width: 2%"></div>
<div class="td" style="width: 2%;"></div>
<div class="td" style="width: 14%;">Name</div>
<div class="td" style="width: 15%;">Company</div>
<div class="td" style="width: 9%;">Type</div>
<div class="td" style="width: 13%;">Phone</div>
<div class="td" style="width: 21%;">Email</div>
<div class="td" style="width: 17%;">City/State</div>
<div class="td" style="width: 8%;">Region</div>
</div>
<div class="tr">
<div class="td"><input type="image" name="Contacts1$rep$ctl01$imgdelbtn" id="Contacts1_rep_ctl01_imgdelbtn" src="images/del.png" style="border-width:0px;" /></div>
<div class="td"><img alt="" src="images/edit.png" style="width: 16px; height: 16px" /></div>
<div class="td">Bob Smith</div>
<div class="td"><a id="Contacts1_rep_ctl01_CompanyLnkBtn" href="javascript:__doPostBack('Contacts1$rep$ctl01$CompanyLnkBtn','')">Ops</a></div>
<div class="td">User</div>
<div class="td">555-555-5555</div>
<div class="td"><a href='mailto:ops#ops.com'>ops#ops.com</a></div>
<div class="td">Ops HI</div>
<div class="td">Midwest</div>
</div>
<div class="tr" style="background-color: #F0F0F0">
<div class="td"><input type="image" name="Contacts1$rep$ctl02$imgdelbtn" id="Contacts1_rep_ctl02_imgdelbtn" src="images/delete.png" style="border-width:0px;" /></div>
<div class="td"><img alt="" src="images/edit.png" style="width: 16px; height: 16px" /></div>
<div class="td">Bob Stevens</div>
<div class="td"><a id="Contacts1_rep_ctl02_CompanyLnkBtn" href="javascript:__doPostBack('Contacts1$rep$ctl02$CompanyLnkBtn','')">ABC CO</a></div>
<div class="td">User</div>
<div class="td">000.000.0000</div>
<div class="td"><a href='mailto:test#test.com'>test#test.com</a></div>
<div class="td">OHHNO CA</div>
<div class="td">Midwest</div>
</div>
</div>
CSS:
div.table
{
border: 1px solid #808080;
display: table;
}
div.tr
{
border: 1px solid #808080;
display: table-row;
}
div.td
{
border: 1px solid #808080;
display: table-cell;
height: 25px;
padding-left: 5px;
padding-right: 5px;
vertical-align: middle ;
}
div.header
{
background-color: #E0E0E0;
font-weight: bold;
}
Rows and columns of logically-associated data belong in a table. DIVs are the wrong tool for the job.
While we've all be told not to use TABLEs, that only applies to using them for layouts. A grid is not a layout, it is a table.
There really is no problem displaying tabular data in a table. That is the point of the table.
Don't feel that you need to display data in div tags.
Why don't you simply use table instead div?
If you look at this table you will see, that IE7 doesn not support "table". I suggest that you try to solve the problem with "float".
IE prior to IE8 doesn't support display: table*
Don't even try. It won't work.