I am trying to create a table with fixed header and scrollable content using Bootstrap.I have gone through many examples but none of them seems to be perfectly working with my code. Either the column alignment is missing or the content itself is not getting a scrollbar to scroll.
Source : I have taken the below example from bootstrap code to fix table header , but it doesn't have any solutions to follow.
Example link to be fixed : https://plnkr.co/edit/5285K3dt5aErj3ZgrzIl?p=preview
HTML code:
<div class="modal-body">
<div class="row">
<div class="" style="width: 80%; margin: 0px auto">
<table class="table table-bordered header-fixed" style="border :1px">
<thead>
<tr style="background-color: #cdd0d6;">
<th style="white-space: wrap;text-align: center;">ID</th>
<th style="white-space: nowrap;text-align: center;">Description</th>
<th style="white-space: wrap;text-align: center;">DoorNum</th>
<th style="white-space: wrap;text-align: center;">First Name</th>
<th style="white-space: wrap;text-align: center;">Num of ordered items</th>
<th style="white-space: wrap;text-align: center;">Desc Comments</th>
</tr>
</thead>
<tbody >
<tr>
<td style="text-align: center;">10</td>
<td style="text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
<td style="text-align: center; ">798</td>
<td style="text-align: center; ">Joe</td>
<td style="text-align: center; ">4</td>
<td style="text-align: center; ">Order dispatched</td>
</tr>
....
</div>
PS: I have followed many links and tried to implement, but have not got the solution yet.
Simply
thead {
position: fixed;
}
Related
Good evening, I'm trying to align a table to make it like the picture, but failed to do so, I could help?
Now I have it like this:
and I'd like it to look like this:
This is my html code:
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-left">Codigo</th>
<th class="text-left">Descripcion</th>
<th class="text-left">Precio</th>
<th class="text-left">Cantidad</th>
<th class="text-left">Importe</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1001</td>
<td class="col-md-8">Producto de ejemplo 1</td>
<td class="col-md-1 text-right">$10,000</td>
<td class="col-md-1 text-center">100</td>
<td class="col-md-1 text-right">$1,000,000</td>
</tr>
<tr>
<th class="text-right" scope="row">TOTAL</th>
<td class="text-right">$1,000,000</td>
</tr>
</tbody>
</table>
Specifying the colspan for the cells in the summary row will shift the final cell right.
<th colspan="4" class="text-right" scope="row">TOTAL</th>
Alternatively, you could start the row with a <td> with colspan="3", and using a class that would have no borders (controlled by your css).
<td colspan="3" class="noborders"></td>
<th class="text-right" scope="row">TOTAL</th>
Without that class, direct manipulation of style may work.
<td style="border:0" colspan="3"></td>
<th class="text-right" scope="row">TOTAL</th>
Updated snippet:
table {
border-collapse: collapse;
font-family: arial;
}
td,
th {
width: auto;
margin: 2px;
padding: 3px;
text-align: left;
border: 1px solid grey;
}
.noborders {
border: 0;
}
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-left">Codigo</th>
<th class="text-left">Descripcion</th>
<th class="text-left">Precio</th>
<th class="text-left">Cantidad</th>
<th class="text-left">Importe</th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">1001</td>
<td class="col-md-8">Producto de ejemplo 1</td>
<td class="col-md-1 text-right">$10,000</td>
<td class="col-md-1 text-center">100</td>
<td class="col-md-1 text-right">$1,000,000</td>
</tr>
<tr>
<td colspan="3" class="noborders"></td>
<th class="text-right" scope="row">TOTAL</th>
<td class="text-right">$1,000,000</td>
</tr>
</tbody>
</table>
I want a table with scrollable body with fixed header.
This is my html code. I am using foundation also.
<div class="large-10 medium-10 small-12 row">
<table style = "height: 13% !important;">
<thead>
<th style="width:150px">Customer TKN</th>
<th style="width:150px">Customer Name</th>
<th style="width:150px">Meter Read Date</th>
<th style="width:100px">Bill Amount</th>
<th style="width:100px">No. of Billing Accounts</th>
<th style="width:100px">No. of Active Accounts</th>
<th style="width:100px">No. of Processed Accounts</th>
<th style="width:150px">title</th>
</thead>
<tbody id="rec_tab_boby">
<tr>
<td id="cust_id" style="width:150px">1234</td>
<td style="width:150px">Mark Jack</td>
<td style="width:150px">2015-08-20</td>
<td style="width:100px">23.55</td>
<td style="width:100px">5</td>
<td style="width:100px">4</td>
<td style="width:100px">4</td>
<td class="status-for-popup" style="width:150px">22</td>
</tbody>
</table>
This id my css
#rec_tab_boby{
height: 80% !important;
overflow-y: scroll;
display: inline-block;
width: 64rem;
}
the code works in chrome and in ie 10 and above but it does not work in ie 9.
What can be the problem?
I feel ie 9 is not taking display: inline-block.
I have tried various options such as overlap and suchlike, but I can't stop a div from overlapping a table to the right.
I have created a fiddle for my code http://jsfiddle.net/ntEzL/ to help explain my issue.
<div style="border: 1px solid #c9c3ba; padding: 0.5em; background-color: #f1f0ee; overflow: hidden;">
<br>
<br>
<table class="ff_sidebox" cellspacing="5" style="width:22em;">Latvia
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
<tr class="">
<th scope="row" style="text-align:left; white-space: nowrap">Full Name</th>
<td class="" style="white-space: nowrap">Republic of Latvia</td>
</tr>
</table>
<!-- end of sidebox for Latvia -->
<br>
<br>
<div class="ff_other_articles_caption" id="recent_articles_caption">Recent articles on Latvia</div>
<div class="ff_other_articles" id="recent_articles">
<div class="ff_other_articles_inner" id="recent_articles_inner">
<ul class="block_list">
<li> Latvia becomes 18th Euro Member on Jan 1st
</li>
</ul>
</div>
</div>
<br>
<br>
<br>
</div>
On a wider screen then there is no issue, but on a smaller resolution then I get the problem.
I would rather the content of the left box (div) to scroll to two lines if it can't fit there.
Any thoughts?
Thanks.
Try this..
for .ff_other_articles styles, remove position: absolute and add width:33%
Remove
position : absolute;
and add
width: 40% !important;
in class 'ff_other_articles' and check the changes i have made in html.
fiddle : http://jsfiddle.net/LPJAa/
Thanks.
why not use css table for this....??
i haved removed <br /> for easier understanding....and removed floats too, as they are not needed if you use floats..here is the demo
html, body {
width:100%;
height:100%;
margin:0;
padding:0;
}
#main_container {
display:table;
width:100%;
border:1px dashed #000;
}
.table_box_1 {
display:table-cell;
width:200px;
border:1px dashed red;
}
.table_box_2 {
display:table-cell;
width:50%;
border:1px dashed red;
}
Both float:left; and position:absolute; cannot be together.In this case remove absolute positioning from the left side box:
If i guess right this is what you asked for:
Fiddle 1 or Fiddle 2
Click to see updated fiddle:- With code / fullscreen
I'm trying to write a table so that it doesn't expand to the full width of the page. Below is what I have so far, but even though the first columns seem to respect the "width" parameter, the last column expands to the end of the page.
All results I found use CSS, but I am not sure how to do that. I don't know if it's relevant, but I'm writing a Joomla! article.
<table class="zebra" width="300">
<thead>
<tr>
<th style="text-align: left;" width="100">title 1</th>
<th style="text-align: center;" width="100">title 2</th>
<th style="text-align: center;" width="100">title 3</th></tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;" width="100">content 1</td>
<td style="text-align: center;" width="100">content 2</td>
<td style="text-align: center;" width="100">content 3</td>
</tr>
</tbody>
</table>
<table class="zebra" style="max-width:300px;">
So far, I'm doing this programmatically using VB.net/ASP.net:
<table cellspacing="0" cellpadding="4" border="0" style="border-
width:0px;width:100%;border-collapse:collapse;font-size:12px;">
<tr>
<td colspan="6"></td>
<td align="center" colspan="3" style="background-color:#F0D3D3;text-
decoration:underline;">SET</td>
<td colspan="2" style="background-color:#CFF5CE;"></td>
<td align="center" colspan="3" style="background-color:#BEE0F7;text-
decoration:underline;">REM</td>
</tr>
<tr>
<th style="width:70px;">M</th>
<th style="width:70px;">PG</th>
<th style="width:70px;">PV</th>
<th style="width:70px;">PDD</th>
<th style="width:40px;">R</th>
<th style="width:55px;">I #</th>
<th style="background-color:#F0D3D3;width:70px;">P A</th>
<th style="background-color:#F0D3D3;width:70px;">U D</th>
<th style="background-color:#F0D3D3;width:70px;">B P</th>
<th style="background-color:#CFF5CE;width:70px;">P U</th>
<th style="background-color:#CFF5CE;width:70px;">D E</th>
<th style="background-color:#BEE0F7;width:70px;">P</th>
<th style="background-color:#BEE0F7;width:70px;">U D</th>
<th style="background-color:#BEE0F7;width:70px;">B P</th>
</tr>
</table>
<div style="width:100%;clear:both;text-align:left;margin:0;">
<div style="width:375px;float:left;margin:0;display:block;">
<img onclick="change(this.parent);" src="minus99.jpg" style="border-width:0px;" />
<span style="font-weight:bold;font-size:16px;">Test Company</span>
</div>
<div style="background-
color:#F0D3D3;width:210px;float:left;margin:0;display:block;"></div>
<div style="background-
color:#CFF5CE;width:140px;float:left;margin:0;display:block;"></div>
<div style="background-
color:#BEE0F7;width:210px;float:right;padding:0;margin:0;display:block;"></div>
</div>
This should give me four DIVS inside a container DIV. Here's what it's coming out as:
The correct blocks above the non-inline blocks are from a table with the same exact widths as the ones I'm using on the Divs. There isn't any CSS adding pixels to them, I don't think. I need to line these up, and I can't figure out where my problem is here.
You can use instead of divs the colspan="[number]", for example:
<table cellspacing="0" cellpadding="4" border="0" style="border-width:0px;width:100%;border-collapse:collapse;font-size:12px;">
<tr>
<td colspan="6"></td>
<td align="center" colspan="3" style="background-color:#F0D3D3;text-decoration:underline;">SET</td>
<td colspan="2" style="background-color:#CFF5CE;"></td>
<td align="center" colspan="3" style="background-color:#BEE0F7;text-decoration:underline;">REM</td>
</tr>
<tr>
<th style="width:70px;">M</th>
<th style="width:70px;">PG</th>
<th style="width:70px;">PV</th>
<th style="width:70px;">PDD</th>
<th style="width:40px;">R</th>
<th style="width:55px;">I #</th>
<th style="background-color:#F0D3D3;width:70px;">P A</th>
<th style="background-color:#F0D3D3;width:70px;">U D</th>
<th style="background-color:#F0D3D3;width:70px;">B P</th>
<th style="background-color:#CFF5CE;width:70px;">P U</th>
<th style="background-color:#CFF5CE;width:70px;">D E</th>
<th style="background-color:#BEE0F7;width:70px;">P</th>
<th style="background-color:#BEE0F7;width:70px;">U D</th>
<th style="background-color:#BEE0F7;width:70px;">B P</th>
</tr>
<tr>
<td colspan="6">
<img onclick="change(this.parent);" src="minus99.jpg" style="border-width:0px;" />
<span style="font-weight:bold;font-size:16px;">Test Company</span>
</td>
<td colspan="3" style="background-color:#F0D3D3;"></td>
<td colspan="2" style="background-color:#CFF5CE;"></td>
<td colspan="3" style="background-color:#BEE0F7;"></td>
</tr>
</table>
Hoped i helped you.. =)
Width: 100% on the table overrides individual column widths. In your table, there are 13 <th>, and each will have a width of 1/13:th of the table's width. A width property on a <th> doesn't do anything. You could force it by adding display: inline-block to the <th>, but I wouldn't want to go that way.
Also, you should set the pink and green divs to float: right in order to remove the white inbetween green and blue (note however that you'll have to change the order of the divs in your code).
Also, I'd suggest using a table instead if you're aiming to present tabular data.
Did you put cellspacing="0" cellpadding="0" on the table? If not, that might be where the difference is coming from.
Or maybe border.
Can you include the table header?