In my view form I have this code for table:
<table class ="table table-bordered">
<colgroup span="7"></colgroup>
<tbody>
<tr ng-repeat="tr in rows">
<td ng-repeat="td in tr track by $index">
<span ng-bind-html="td"></span>
</td>
</tr>
</tbody>
Now I want to change from table to div and below is my code:
<div ng-repeat = "tr in rows">
<div ng-repeat="td in tr track by $index">
<div><span ng-bind-html="td"></span></div>
</div>
</div>
But it's not work I try to add some css like this:
<style type="text/css">
div.inline { float:left; }
.clearBoth { clear:both; }
</style>
It doesn't work at all. . Any suggestions?
Indeed <div> tags alone won't do anything and you need CSS.
Here are two different ways to achieve this (see code below):
use display: table, table-row, table-cell for your div to behave like an actual <table>
use display: flex to use the advantages of Flexboxes introduced by CSS3 (not compatible with older browsers)
Live example:
angular.module('test', []).controller('ctrl', function($scope) {
$scope.rows = [['0.0','0.1','0.2'], ['1.0','1.1','1.2']];
});
.cell { padding: 10px; border: 1px solid #999; }
.table { display: table }
.table .row { display: table-row; }
.table .cell { display: table-cell; }
.flexbox { display: flex; flex-direction: column; }
.flexbox .row { display: flex; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="test" ng-controller="ctrl">
Example using table CSS
<div class="table">
<div class="row" ng-repeat="tr in rows">
<div class="cell" ng-repeat="td in tr track by $index">
{{td}}
</div>
</div>
</div>
<br><br>
Example using flexbox
<div class="flexbox">
<div class="row" ng-repeat="tr in rows">
<div class="cell" ng-repeat="td in tr track by $index">
{{td}}
</div>
</div>
</div>
</div>
Related
Here is an example, containing a table element with multiple tbody elements
https://jsfiddle.net/aoLbuafx/
HTML
<table>
<tbody class="tbody1">
<tr>
<td>Eka</td>
<td>Toka</td>
<td>Kolmas</td>
</tr>
</tbody>
<tbody class="tbody2">
<tr>
<td>Sisältö</td>
<td>Sisältö</td>
<td>Sisältö</td>
</tr>
<tr>
<td>Sisältö</td>
<td>Sisältö</td>
<td>Sisältö</td>
</tr>
<tr>
<td>Sisältö</td>
<td>Sisältö</td>
<td>Sisältö</td>
</tr>
</tbody>
<tbody class="tbody3">
<tr>
<td>Eka</td>
<td>Toka</td>
<td>Kolmas</td>
</tr>
</tbody>
</table>
CSS
table {
height: 500px;
}
.tbody1 {
background-color: red;
}
.tbody2 {
background-color: blue;
}
.tbody3 {
background-color: green;
}
The end results is that browsers render this table very differently. Firefox shares the total height between tbody elements equally, while Chrome prefers to use the first tbody to fill the available space.
Is is possible to help Chrome render the table as Firefox does, sharing the height between tbody elements, while keeping the table height fixed?
Sidenote: Changing the first tbody to thead and the last tbody to tfoot helps a bit, since in this case Chrome prefers the one and only tbody element to fill the available space. Still, it is not what I want.
That's interesting behavior. Without using Javascript to count children and set height accordingly, this can be done with a flexboxes (as can many things).
Here's the HTML:
<div class="table">
<div class="wrap tbody1">
<div class="cell">Eka</div>
<div class="cell">Toka</div>
<div class="cell">Kolmas</div>
</div>
<div class="wrap tbody2">
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
</div>
<div class="wrap tbody2">
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
</div>
<div class="wrap tbody2">
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
<div class="cell">Sisältö</div>
</div>
<div class="wrap tbody3">
<div class="cell">Eka</div>
<div class="cell">Toka</div>
<div class="cell">Kolmas</div>
</div>
</div>
And the CSS:
.wrap {
display: flex;
flex: 1;
justify-content: space-between;
}
.cell {
display: flex;
width: 100%;
padding: 5px;
}
.table {
height: 500px;
display: flex;
flex-direction: column;
}
Here's a JSFiddle with some added styles. The property in the flexbox that allows heights to be evening out is the flex:1 on .wrap.
I want to create something like this using divs and it also should be without using display:table css rule etc. How do I create table header this??
May be try this as a starting point? You might need to tweak it a lot.
* {box-sizing: border-box;}
.row {overflow: hidden; clear: both;}
.cell {border: 1px solid #999; padding: 0px; float: left;}
.cell.full {float: none;}
.col-1 {width: 20%;}
.col-2 {width: 40%;}
.col-3 {width: 60%;}
.col-33 {width: 33.3%;}
.row-2 {height: 3em;}
<div class="row">
<div class="cell col-1 row-2">Subject</div>
<div class="cell col-3 row-2">
<div class="row">
<div class="cell full">First Term</div>
</div>
<div class="row">
<div class="cell col-33">October Test</div>
<div class="cell col-33">December Exam</div>
<div class="cell col-33">Term Average</div>
</div>
</div>
<div class="col-1 row-2 cell">Teacher's Evaluation</div>
</div>
Preview:
If you can use flexbox can i use flexbox
The benefit of using flexbox is that you can get the the same result as you using the table tag including vertical-align:middle.
In the snippet, keep attention to the text-alignment in the cells.
You can use flexboxgrid like this:
[class*="col"] {
text-align:center;
border:1px solid;
display: flex;
justify-content: center;
flex-direction: column;
}
<link href="http://cdn.jsdelivr.net/flexboxgrid/6.3.0/flexboxgrid.min.css" rel="stylesheet" />
<div class="row ">
<div class="col-xs-3">Subject</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12">First Term</div>
</div>
<div class="row">
<div class="col-xs-4">October Test</div>
<div class="col-xs-4">December Exam</div>
<div class="col-xs-4">Term Average</div>
</div>
</div>
<div class="col-xs-3">Teacher's Evaluation</div>
</div>
The result:
http://jsbin.com/zetaro/edit?html,css,output
Just use colspan and rowspan =)
tutorial how to do it
I made it:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
<table>
<tr>
<th rowspan="2"><br>Subject<br></th>
<th colspan="3">First term</th>
<th rowspan="2">Teacher's Evaluation</th>
</tr>
<tr>
<td>October test</td>
<td>December exam</td>
<td>Term Average</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
https://jsfiddle.net/b3aqLny1/
Try this
.table {
width: 100%;
table-layout: fixed;
display: table;
text-align: center;
}
.table .row{
display: table-row;
}
.table .row .col {
display: table-cell;
vertical-align: middle;
height: 100px;
border: 2px solid #333;
width: 33%;
}
.table .col.col-big {
width: 50%;
}
span {
display: inline-block;
padding: 10px;
}
.inner-table.table .row .col {border-width: 1px;}
<div class="table">
<div class="row">
<div class="col">
<span>Subject</span>
</div>
<div class="col col-big">
<div class="table inner-table">
<div class="row">
<div class="col one-col" style="width: 100%">
<span>First Term</span>
</div>
</div>
<div class="row">
<div class="table inner-table">
<div class="row">
<div class="col"><span>Test 1</span></div>
<div class="col"><span>Test 2</span></div>
<div class="col"><span>Test 3</span></div>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<span>Teacher's Evaluation</span>
</div>
</div>
</div>
I need to set <div id="group-of-tables"> to the bottom of the <div class="item-content">, and without using absolute position.
HTML:
<div class="item-content">
<div id="group-of-tables">
<table class="item" id="first-table">
<tr>
<td><div class="" id="">1</div></td>
<td><div class="" id="">2</div></td>
<td><div class="" id="">3</div></td>
<td><div class="" id="">4</div></td>
</tr>
</table>
<table class="item" id="second-table" border="1">
<tr>
<td><div class="" id="">Next</div></td>
</tr>
</table>
</div>
</div>
CSS:
.item-content{
height:100%;
}
Something like this:
You could do it with CSS flex, and don't forget to prefix all the flex related rules to make it to work more browsers, visit this link to see more support details, visit this link to learn more.
JsFiddle Demo
html, body {
height: 100%;
margin: 0;
}
.wrap {
height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.top {
flex: 1;
}
<div class="wrap">
<div class="top">Top</div>
<div class="bottom">Bottom</div>
</div>
I'm building out a hierarchical (recursive) table using Angular. Unfortunately angular's directives are part of the HTML DOM and combined with recursion I end up with nested table elements. I am trying to use CSS table layout rather than the classic <table> elements.
Using table elements everything lays out okay:
<table>
<tr>
<td class="cell">one</div>
<td class="cell">two</div>
<td class="cell">three</div>
</tr>
<tbody>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
<tbody>
<tr>
<td>one</td>
<td>two</td>
<td>three</td>
</tr>
</tbody>
</tbody>
</table>
But if I try to do the same things using CSS the layout gets screwed up:
<style>
.table {
display: table;
width: 100%;
table-layout: fixed;
}
.row {
display: table-row;
}
.cell {
display: table-cell
}
.nolayout {
display: table-row-group
}
</style>
<div class="table">
<div class="row">
<div class="cell">one</div>
<div class="cell">two</div>
<div class="cell">three</div>
</div>
<div class="nolayout">
<div class="row">
<div class="cell">one</div>
<div class="cell">two</div>
<div class="cell">three</div>
</div>
<div class="nolayout">
<div class="row">
<div class="cell">one</div>
<div class="cell">two</div>
<div class="cell">three</div>
</div>
</div>
</div>
</div>
Here's a jsfiddle showing the problem:
http://jsfiddle.net/LjyLz2Le/7/
please change
.nolayout {
display: table-row-group
}
to
.nolayout div {
display: table-row-group
}
Because the nolayout class assign only for the main div, does not sub div. you need assign table-row-group for your cell div
Working Demo
I want to use div elements to create a table-like layout.
What I want
.tableStyle td {
background: red;
color: #fff
}
.contentBox {
min-height: 200px;
}
<table class="tableStyle" width="100%" cellspacing="10">
<tr>
<td width="25%">
<div class="contentBox">One</div>
</td>
<td width="25%">Two</td>
<td width="50%" colspan="2">Three</td>
</tr>
<tr>
<td colspan="2">
<div class="contentBox">Four</div>
</td>
<td colspan="2">Five</td>
</tr>
</table>
What I have
.table {
display: table;
width: 100%;
border-collapse: separate;
border-spacing: 10px;
color: #fff
}
.table .row {
display: table-row;
}
.table .table-cell {
display: table-cell;
background: red;
width: 50%;
}
.contentBox {
min-height: 200px;
}
.table .smlCell {
width: 25%;
}
.table .table {
border-spacing: 0;
}
<div class="table">
<div class="row">
<div class="table-cell">
<div class="table">
<div class="row">
<div class="table-cell smlCell">
<div class="contentBox">One</div>
</div>
<div class="table-cell smlCell">
Two
</div>
</div>
</div>
</div>
<div class="table-cell">Three</div>
</div>
<div class="row">
<div class="table-cell">
<div class="contentBox">Four</div>
</div>
<div class="table-cell">Five</div>
</div>
</div>
I want to have equal spacing between the cells marked "One" and "Two".
I also want all cells in a row to be of same height.
After searching on net, I know that there are some limitations or issues
for display: table such as a lack of colspan/rowspan equivalents which may help what I'm trying to accomplish.
Is there anyway (apart form <table>) to create this?
Sure there is!
Demo Fiddle
HTML
<div class='table'>
<div class='row'>
<div class='table'>
<div class='cell'>One</div>
<div class='cell'>Two</div>
</div>
<div class='cell'>Three</div>
</div>
<div class='row'>
<div class='cell'>Four</div>
<div class='cell'>Five</div>
</div>
</div>
CSS
html, body{
width:100%;
height:100%;
margin:0;
padding:0;
}
.table {
display:table;
width:100%;
height:100%;
}
.cell {
display:table-cell;
width:50%;
}
.row {
display:table-row;
}
.cell {
background:red;
color:white;
border:5px solid white;
}
Try this. I have used inline instead of CSS class. You had placed one div in wrong location.
<div class="table">
<div class="row">
<div class="table-cell">
<div class="table">
<div class="row">
<div class="table-cell smlCell">
<div style="width:50% float: left" class="contentBox">One
</div>
<div style="width:50% float: right" class="contentBox">
Two
</div>
</div>
</div>
</div>
</div>
<div class="table-cell">Three</div>
</div>
<div class="row">
<div class="table-cell">
<div class="contentBox">Four</div>
</div>
<div class="table-cell">Five</div>
</div>
</div>
with support for older (ms-explorer?). But if your content is table by it's nature, use table and not those tricks :-)
<!DOCTYPE HTML>
<html>
<head>
<title>Bla!</title>
<style type='text/css'>
/* reset sizing model ... */
* { box-sizing: border-box; -webkit-box-sizing: border-box;-moz-box-sizing: border-box; }
/* basic div definitions */
div { display:inline-block; min-height:50px; background-color:red; border:solid 3px white; }
/* 1/2 line div */
div.half { width:50%; }
/* 1/4 line div */
div.quater { width:25%; }
</style>
</head>
<body class='body' id='body' >
<div class='quater'> One </div><div class='quater'> Two </div><div class='half'> Three </div><div class='half'> Four </div><div class='half'> Five </div>
</body>
</html>