The task is pretty strange. I have to create html table BUT I'm not allowed to use traditional <table> tag. My table should look like this:
It would be easy to do it like below:
<table>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="5"></td>
</tr>
...
but, as I said, I'm not allowed to use traditional table tags (table, tr, td, th). Here is JSFIddle of what I have at the moment. How can I get the same result as with <td colspan="5"></td> but using only divs and CSS.
EDITS:
* Table cell's width in one row must not be fixed, it should be dynamic and it should be possible to make them (cells) different width (in one row).
* Table cell's width in different rows of the same column must be equal. Like in traditional table. Only "colspanned" cell's width must be different.
As stated in CSS 2.1 specification in part "17.5 Visual layout of table contents"
Cells may span several rows or columns. (Although CSS 2.1 does not define how the number of spanned rows or columns is determined ...
So the answer is easy! Don't think of CSS tables exactly the same as HTML tables. As there are some differences like what mentioned in "17.2.1 Anonymous table objects":
... the "missing" elements must be assumed in order for the table model to work. Any table element will automatically generate necessary anonymous table objects around itself, consisting of at least three nested objects corresponding to a 'table'/'inline-table' element, a 'table-row' element, and a 'table-cell' element. ...
So you can do it this way (each row as a table and dropped table-row for avoiding unnecessary div block) until they specify a way for defining number of spanned rows or columns:
CSS
.row {
display: table;
width: 100%;
}
.cell {
display: table-cell;
width: 16.67%;
}
.wideCell {
display: table-cell;
}
HTML
<div class="row">
<div class="cell">One</div>
<div class="cell">Two</div>
<div class="cell">Three</div>
<div class="cell">Four</div>
<div class="cell">Five</div>
<div class="wideCell">Six</div>
</div>
<div>One Two Three Four Five Six</div>
<div class="row">
<div class="cell">One</div>
<div class="cell">Two</div>
<div class="cell">Three</div>
<div class="cell">Four</div>
<div class="cell">Five</div>
<div class="wideCell">Six</div>
</div>
You need to use CSS float and width to get the table-like effect you're looking for. What I'm basically doing is I'm placing 5 divs all with a fixed width and class name, and floating them to the left. The wideCell has the same width the .wrapper which just holds them all together in a nice block.
HTML
<div class="wrapper">
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="wideCell"></div>
</div>
CSS
.wrapper {
width:510px;
}
.cell {
width:100px;
height:50px;
background-color:#ff0000;
float:left;
border:1px #000 solid;
}
.wideCell {
width:508px;
height:50px;
background-color:#ff0000;
float:left;
border:1px #000 solid;
}
DEMO
EDIT
CSS
.table{
width: 100%;
}
.table .row{
width: 100%;
height: 25px;
margin: 0px;
padding: 0px;
}
.table .row .cell{
width: 150px;
float: left;
border: solid 1px #CCC;
height: 25px;
}
.table .clear_float{
clear: both;
}
.table .row .cell.rowspan{
width: 759px;
border: solid 1px #CCC;
}
html
<div class="table">
<div class="row">
<div class="cell">One</div>
<div class="cell">Two</div>
<div class="cell">Three</div>
<div class="cell">Four</div>
<div class="cell">Five</div>
</div>
<div class="clear_float" />
<div class="row">
<div class="cell rowspan">
One Two Three Four Five
</div>
</div>
<div class="clear_float" />
<div class="row">
<div class="cell">One</div>
<div class="cell">Two</div>
<div class="cell">Three</div>
<div class="cell">Four</div>
<div class="cell">Five</div>
</div>
<div class="clear_float" />
<div class="row">
<div class="cell rowspan">
One Two Three Four Five
</div>
</div>
<div class="clear_float" />
<div class="row">
<div class="cell">One</div>
<div class="cell">Two</div>
<div class="cell">Three</div>
<div class="cell">Four</div>
<div class="cell">Five</div>
</div>
<div class="clear_float" />
<div class="row">
<div class="cell rowspan">
One Two Three Four Five
</div>
</div>
</div>
I have searched a lot there is nothing like colspan in display:table CSS.
You can try this: CSS display:table
<div style="display:table;">
<div style="display:table-row;">
<span style="display:table-cell;">Name</span>
<span style="display:table-cell;"><input type="text"/></span>
</div>
<div style="display:table-row;">
<span style="display:table-cell;">E-Mail</span>
<span style="display:table-cell;"><input type="text"/></span>
</div>
<div style="display:table-row;">
<span style="display:table-cell;">Password</span>
<span style="display:table-cell;"><input type="text"/></span>
</div>
</div>
<div style="display:table;">
<div style="display:table-row; " >
<span style="display:table-cell;">
<button>Send Message</button>
</span>
</div>
</div>
You can do this ( where data-x has the appropriate display:xxxx set ):
<!-- TH -->
<div data-tr>
<div data-th style="width:25%">TH</div>
<div data-th style="width:50%">
<div data-table style="width:100%">
<div data-tr>
<div data-th style="width:25%">TH</div>
<div data-th style="width:25%">TH</div>
<div data-th style="width:25%">TH</div>
<div data-th style="width:25%">TH</div>
</div>
</div>
</div>
<div data-th style="width:25%">TH</div>
</div>
<!-- TD -->
<div data-tr>
<div data-td style="width:25%">TD</div>
<div data-th style="width:50%">
<div data-table style="width:100%">
<div data-tr>
<div data-td style="width:25%">TD</div>
<div data-td style="width:25%">TD</div>
<div data-td style="width:25%">TD</div>
<div data-td style="width:25%">TD</div>
</div>
<div data-tr>
...
</div>
</div>
</div>
<div data-td style="width:25%">TD</div>
</div>
Check this fiddle out i hope that would suffice what you need
html tables
CSS
div.table {border: 1px solid black; display: table; }
div.tr {border: 1px solid black; display: table-row; }
div.td {border: 1px solid black; display: table-cell; }
Html
<div class="table">
<div class="tr">
<div class="td">Row 1, Cell 1</div>
<div class="td">Row 1, Cell 2</div>
<div class="td">Row 1, Cell 3</div>
</div>
<div class="tr">
<div class="td">Row 2, Cell 1</div>
<div class="td">Row 2, Cell 2</div>
<div class="td">Row 2, Cell 3</div>
</div>
Related
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;
}
Here is my HTML Code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<!-- <div class="stack"> -->
<!-- Row 1 -->
<div class="stack">
<div class="row">
<div class="col" align="center">
<span style="font-weight: bold;">States of India</span>
</div>
<div class="col"></div>
<div class="col" align="center">
<span style="font-weight: bold;">United States</span>
</div>
</div> <!-- End of div row class -->
<div class="row">
<div class="col" align="center">Tamil Nadu</div>
<div class="col" align="center">Karnataka</div>
<div class="col" align="center">California</div>
</div> <!-- End of div row class -->
<div class="row">
<div class="col">
<div id="bloc11" class="donutSize">row 1 - column 1</div>
</div>
<div class="col">
<div id="bloc12" class="donutSize">row 1 - column 2</div>
</div>
<div class="col">
<div id="bloc13" class="donutSize">row 1 - column 3</div>
</div>
</div> <!-- End of div row class -->
<div class="row">
<div class="col">
<div id="bloc21">row 2 - column 1</div>
</div>
<div class="col">
<div id="bloc22">row 2 - column 2</div>
</div>
<div class="col">
<div id="bloc23">row 2 - column 3</div>
</div>
</div><!-- End of div row class -->
</div><!-- End of div stack class -->
<!-- </div> -->
<div class="stack2">
<div class="row">
<div class="col">United States & India</div>
</div>
<div class="row">
<div class="col">
<div id="skywalk-module" class="ssSize">United States and India are one of the 2 countries in the world. blah blah b</div>
</div>
</div><!-- End of div row class -->
</div><!-- End of div stack2 class -->
</body>
</html>
Css:
.stack .row,
.stack2 .row {
clear: both
}
.stack .row .col,
.stack2 .row .col {
float: left;
height: auto;
border: 1px groove
}
.stack .row .col {
width: 33%;
align-items: center
}
.stack2 .row .col {
width: 99%;
align-items: center
}
.donutSize {
width: 160px;
height: 160px;
margin: 0 auto
}
Need to align the "States of India" to be entered between "Tamil Nadu" and "Karnataka". Also no need of a border here, align it to centre, something like "colspan =2" when we use html table's.
I want a think line above "States of India", "United States" and "Karnataka".(see image label:need think border line here)
3.I want the last 2 rows , width to be in the same line as the first 4 rows. width is not coming in the same. As you can see last 2 lines are not having same width as first 4 , it has somewhat less width(see image label : align the line straight)
I want to use the DIV tags and don't want to use tables along for my own reason. I am ok with table used along with the div tags. I need div tags for each of my containers e.g.) states of india, united states, tamil nadu, karnataka, etc.
I am not able to solve this. please help.
Here is my code in JSBIN.
http://jsbin.com/fasacu/4/edit?html,css,output
I have followed the suggestion from #Quantastical + some other stack overflow answers.
HTML Code:
<!-- Row 1 -->
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col1" align="center">
<span style="font-weight: bold;">States of India</span>
</div>
<div class="div-table-col" align="center">
<span style="font-weight: bold;">United States</span>
</div>
</div> <!-- End of div row class -->
</div>
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col3" align="center">Tamil Nadu</div>
<div class="div-table-col3" align="center">Karnataka</div>
<div class="div-table-col3" align="center">California</div>
</div> <!-- End of div row class -->
<div class="div-table-row">
<div class="div-table-col3">
<div id="bloc11" class="donutSize">row 1 - column 1</div>
</div>
<div class="div-table-col3">
<div id="bloc12" class="donutSize">row 1 - column 2</div>
</div>
<div class="div-table-col3">
<div id="bloc13" class="donutSize">row 1 - column 3</div>
</div>
</div> <!-- End of div row class -->
<div class="row">
<div class="div-table-col3">
<div id="bloc21">row 2 - column 1</div>
</div>
<div class="div-table-col3">
<div id="bloc22">row 2 - column 2</div>
</div>
<div class="div-table-col3">
<div id="bloc23">row 2 - column 3</div>
</div>
</div><!-- End of div row class -->
</div><!-- End of div table class -->
<!-- </div> -->
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col2">United States & India</div>
</div>
</div>
<div class="div-table">
<div class="div-table-row">
<div class="div-table-col2">
<div id="skywalk-module" class="ssSize">United States and India are one of the 2 countries in the world. blah blah b</div>
</div>
</div><!-- End of div row class -->
</div><!-- End of div table class -->
Css:
.div-table{
display:table;
width:auto;
border:1px solid #666666;
}
.div-table-row{
display:table-row;
width:auto;
clear:both;
}
.div-table-col{
float:left;/*fix for buggy browsers*/
display:table-column;
width:200px;
border:1px solid #666666;
}
.div-table-col3{
float:left;/*fix for buggy browsers*/
display:table-column;
width:200px;
border:1px solid #666666;
}
.div-table-col1{
float:left;/*fix for buggy browsers*/
display:table-column;
width:200px;
width:400px;
text-align:center;
border:1px solid #666666;
}
.div-table-col2{
float:left;/*fix for buggy browsers*/
display:table-column;
width:600px;
border:0px solid #666666;
}
Here is the link:
http://jsbin.com/fasacu/15/edit?html,css,output
i suggest using the table element with the cell elements associated with it instead of div tags.
For example, for your table column headings:
<table>
<tr>
<th colspan="2">India</th>
<!--table header cells by default center text both horizontally and vertically.-->
</tr>
</table>
For the alignment,:
<table>
<tr>
<th>header</th>
<th>header2</th>
<th>header3</th>
</tr>
<tr>
<td colspan="3">text string</td>
</tr>
</table>
For the border, one could style the table using css. you can add cell-spacing, set border styles differently for the cells and the table itself, etc.
Interesting that you are using divs instead of the table element to organize info. the table element keeps it all tidy, and instead of every tag beginning with "div", you can identify which elements affect rows (tr), header cells (th), and the data cells (td).
have a good week.
I want to create a row at the very top of a page, and another row hovering the previous one. The idea is to create two columns in the first row - col-md-3 and col-md-9, and the second row is to apply an image between those two, so the row has col-md-2, col-md-2 (image between), col-md-8. It should look like this:
I managed to create it, but the box between is still not fixed:
<div class="container-fluid">
<div style="position: absolute; width: 100%;">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-2" style="text-align: center; z-index: 9999;">
<div style="background-color: red;"> # Adding position: fixed here works but breaks box width
<img src="/assets/image/logo.jpg">
<br>
Something
</div>
</div>
<div class="col-md-8"></div>
</div>
</div>
<div class="row" style="height: 100%;">
<div class="col-md-3" style="position: relative;">
<div>
<img src="/assets/image/leftImage.jpg">
</div>
</div>
<div class="col-md-1"></div>
<div class="col-md-8">
Lorem ipsum...
</div>
</div>
</div>
How can I do that?
You dont have to use bootstrap, You can use css:
div.container
{
width:100%;
position:fixed;
background-color:red;
height:100px;
}
div.img
{
margin:auto;
width:80%;
padding:5px;
text-align:center;
}
If you check the fiddle you can understand it better.
I am trying to make 2 columns, underneath one of the column need to have 3 rows. each rows has seperate number of cells. but it's not working for me. it should 100% wide, but it look like inline-table - how to fix this?
#table {
display:table;
width:100%
}
.row {
display:table-row;
}
.cell {
display:table-cell;
border:1px solid grey;
}
.row1 {
display: table-caption;
}
.cell1 {
width:30%
}
<div id="table">
<div class="row">
<div class="cell cell1">30%</div>
<div class="cell cell2">
<div class="row row1">
<div class="cell"><h2>90%</h2></div>
<div class="cell"><h2>10%</h2></div>
</div>
<div class="row row2">
<div class="cell"><h2>40%</h2></div>
<div class="cell"><h2>20%</h2></div>
<div class="cell"><h2>20%</h2></div>
<div class="cell"><h2>20%</h2></div>
</div>
<div class="row row2">
<div class="cell"><h2>100%</h2></div>
</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>