I created a table using bootstrap, and put it in a div of class container-fluid. On a desktop view it looks like this:
In my CSS I used #media in order to determine certain width under which my container-fluid will take 100% of the screen, but still on mobile view, part of the right side of the table is hidden, and I have to horizontally scroll in order to see it. It looks like this:
My relevant html code is:
<div class="container-fluid" id="tableCont">
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Product Name</th>
<th title="Quantity of the product" scope="col">Quantity</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Tomato </td>
<td><input type="number" min="1" max="50"></td>
<td><button title="Include product in list">Include</button></td>
<td> <button type="button" class="btn btn-labeled btn-danger">
<span class="fa fa-remove"></span> Remove</button>
</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Potato</td>
<td><input type="number" min="1" max="50"></td>
<td><button title="Include product in list">Include</button></td>
<td> <button type="button" class="btn btn-labeled btn-danger">
<span class="fa fa-remove"></span> Remove</button></td>
</tr>
My relevant CSS is:
.table {
width: 100%;
}
#tableCont {
margin-top: 0;
height: 400px;
overflow-y: auto;
border: white;
width: 68%;
}
#media (max-width: 600px) {
#tableCont {
width: 100%;
}
}
How can I set the mobile view so the whole width of the table will be visible with no horizontal scrolling?
Try changing width to max-width in media query.
#media (max-width: 600px) {
#tableCont {
max-width: 100%;
}
put this in your head tag Html:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
and on your CSS:
.table {
display: flex;
justify-content: center;
margin: 0 auto;
width: fit-content;
}
and if you want your content to start from the left side and still fit the screen put this code in #tableCont:
#tableCont {
display: inline-block;
float: left;
}
you can solve this problem with CSS grid as well, so if that interests you
visit https://www.w3schools.com/css/css_grid.asp
I have run into following issue. I am displaying a table with data on a page, which is nested in main . Its margin-left isset to 5% (margin-right too) and it has defined width. For some reason when I load the page in Chrome, the left margin is ignored. And here it gets interesting. When I open dev console it gets applied. If I reload the page with console open, it gets broken again. When I turn off any css setting in the console (or basicaly touch anything related to content) it gets fixed again. I am using Unsemantic framework for responsive behavior (only desktop part of it) and I had no trouble with it so far, just this. And since it behaves this strangely, I dont think it has anything to do with the code.
You can see it clearly on this short screencap: http://screencast.com/t/mGotS01iC
Just to be sure, I am posting HTML and CSS for the element:
<table class="grid-90 prefix-5 suffix-5">
<tbody>
<tr>
<th> UserName </th>
<th> Email </th>
<th> Guid </th>
<th> IsUsingTempPasswd </th>
<th> LastLogin </th>
<th> PasswordChanged </th>
<th>Actions</th>
</tr>
<tr>
<td> Administrator </td>
<td> admin#physter.com </td>
<td>
<div class="table-long">00000002-0000-0000-0000-000000000069</div>
</td>
<td class="cell-checkbox">
<input class="check-box" type="checkbox" disabled="disabled">
</td>
<td> </td>
<td> 26.7.2013 12:11:06 </td>
<td class="actions">
Edit
|
Details
|
Delete
|
Reset Password
</td>
</tr>
<tr>
<td> venca </td>
<td> venca#mail.cz </td>
<td>
<div class="table-long">00000002-0000-0000-0000-00000000006a</div>
</td>
<td class="cell-checkbox">
<input class="check-box" type="checkbox" disabled="disabled">
</td>
<td> 23.8.2013 12:23:39 </td>
<td> 26.7.2013 12:11:06 </td>
<td class="actions">
Edit
|
Details
|
Delete
|
Reset Password
</td>
</tr>
<tr>
<td colspan="7">
Create New
</td>
</tr>
</tbody>
</table>
Here is CSS for the element:
grid-90 {
float: left;
width: 90%;
}
.suffix-5 {
margin-right: 5%;
}
.prefix-5 {
margin-left: 5%;
}
.grid-5, .mobile-grid-5, .tablet-grid-5, .grid-10, .mobile-grid-10, .tablet-grid-10, .grid-15, .mobile-grid-15, .tablet-grid-15, .grid-20, .mobile-grid-20, .tablet-grid-20, .grid-25, .mobile-grid-25, .tablet-grid-25, .grid-30, .mobile-grid-30, .tablet-grid-30, .grid-35, .mobile-grid-35, .tablet-grid-35, .grid-40, .mobile-grid-40, .tablet-grid-40, .grid-45, .mobile-grid-45, .tablet-grid-45, .grid-50, .mobile-grid-50, .tablet-grid-50, .grid-55, .mobile-grid-55, .tablet-grid-55, .grid-60, .mobile-grid-60, .tablet-grid-60, .grid-65, .mobile-grid-65, .tablet-grid-65, .grid-70, .mobile-grid-70, .tablet-grid-70, .grid-75, .mobile-grid-75, .tablet-grid-75, .grid-80, .mobile-grid-80, .tablet-grid-80, .grid-85, .mobile-grid-85, .tablet-grid-85, .grid-90, .mobile-grid-90, .tablet-grid-90, .grid-95, .mobile-grid-95, .tablet-grid-95, .grid-100, .mobile-grid-100, .tablet-grid-100, .grid-33, .mobile-grid-33, .tablet-grid-33, .grid-66, .mobile-grid-66, .tablet-grid-66 {
-moz-box-sizing: border-box;
padding-left: 10px;
padding-right: 10px;
}
table {
border: medium none;
margin-bottom: 2.5em;
margin-top: 1em;
text-align: left;
width: 100%;
}
body {
color: #006666;
font-family: "Segoe UI",Verdana,Helvetica,Sans-Serif;
font-size: 0.85em;
}
Anybody has an idea? I would be grateful for solution that would allow me keep the framework as it is and do not overwrite its behavior...
Width of 90% and the fact that you want the table on center are enough. The edges will be calculated automatically. So your code would look like this:
CSS
grid-90 {
width: 90%; }
.grid-5, .mobile-grid-5, .tablet-grid-5, .grid-10, .mobile-grid-10, .tablet-grid-10, .grid-15, .mobile-grid-15, .tablet-grid-15, .grid-20, .mobile-grid-20, .tablet-grid-20, .grid-25, .mobile-grid-25, .tablet-grid-25, .grid-30, .mobile-grid-30, .tablet-grid-30, .grid-35, .mobile-grid-35, .tablet-grid-35, .grid-40, .mobile-grid-40, .tablet-grid-40, .grid-45, .mobile-grid-45, .tablet-grid-45, .grid-50, .mobile-grid-50, .tablet-grid-50, .grid-55, .mobile-grid-55, .tablet-grid-55, .grid-60, .mobile-grid-60, .tablet-grid-60, .grid-65, .mobile-grid-65, .tablet-grid-65, .grid-70, .mobile-grid-70, .tablet-grid-70, .grid-75, .mobile-grid-75, .tablet-grid-75, .grid-80, .mobile-grid-80, .tablet-grid-80, .grid-85, .mobile-grid-85, .tablet-grid-85, .grid-90, .mobile-grid-90, .tablet-grid-90, .grid-95, .mobile-grid-95, .tablet-grid-95, .grid-100, .mobile-grid-100, .tablet-grid-100, .grid-33, .mobile-grid-33, .tablet-grid-33, .grid-66, .mobile-grid-66, .tablet-grid-66 {
-moz-box-sizing: border-box;
padding-left: 10px;
padding-right: 10px;
}
table {
border: medium none;
margin-bottom: 2.5em;
margin-top: 1em;
text-align: left;
margin: 0 auto;
}
body {
color: #006666;
font-family: "Segoe UI",Verdana,Helvetica,Sans-Serif;
font-size: 0.85em;
}
In HTML remove the names of the two divisions: <table class="grid-90"> I hope that helps!
Only thing needed was a little "hack" - adding float:none !important; to <table> elelemnt was enough.
Thanks to Dragos Sandu who put me up to this - removing float:left from grid-90 class was his idea and first step I tried.
I have created a table http://jsfiddle.net/vR5B8/.
table id="resultDetails" class="table-striped" border=1 width="99%" nowrap=0; cellspacing=0; cellpadding=3><tbody>
<th colspan="2"><Big>Result Details</Big></th>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules
<div class="content">
<p>Abc</p>
</div>
</td>
</tr>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules 1</td>
</tr>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules 2</td>
</tr>
</tbody>
Some of the rows contain additional information which is hidden. If the row contains hidden information, then the height of row is increasing compare to the row which does not contain the hidden information. How to set the common height for all rows.
Any thoughts ?
Use display: none instead of visibility hidden demo
tr {
height: 50px;
}
for example :) or
tr {
height: auto;
}
depends of what you need :)
The table row height will increase dynamically in height if more information is added, but to hide an element, use display: none and to give a height to a row, use line-height: /* size */;
.content {
display:none;
}
tr {
min-height: 20px;
line-height: 20px;
}
Here's the jsFiddle
This is the code sample of a simple list display with a scroll button..It is working good. But now i want to freeze first row..that is the header..Can you please help me..
<div id="user">
<table class="user_list" frame="box" bordercolor="#c1a3cf"
border="1" cellspacing="3" cellpadding="3">
<thead>
<tr>
<th style="padding-top:15px;"> Nr. </th>
<th style="padding-top:15px;"> Concession Nr. </th>
<th style="padding-top:15px;"> Action Performed </th>
<th style="padding-top:15px;"> Action by </th>
<th style="padding-top:15px;"> Action on </th>
</tr>
</thead>
<tbody>
<?php $result = get_user_actionlog($seite,$entries);
if($seite == 1) {
$number = 0;
} else {
$number = ($seite-1) * $entries;
}
while($record = odbc_fetch_array($result)) { ?>
<tr>
<td width="25" class="rtodata"><?php $number += 1;
echo $number;?></td>
<td width="150" class="rtodata"><?php echo $record['concession']; ?> </td>
<td width="400" class="rtodata"><?php echo $record['action_performed'];?></td>
<td width="75" class="rtodata"><?php echo $record['action_by'];?></td>
<td width="100" class="rtodata"><?php echo $record['action_on'];?></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
and in my CSS file,
#user {width: 900px;height:800px;overflow:auto;}
EDIT:-
scrollable table with fixed header works perfectly in IE 6.0 nad in Firefox but not in IE 7.0. If any of you champs can update that...
You can do this by adding a class to the <thead> and using position: fixed; You'll need to add some padding to your div to make it display as you wish.
Example for you here.
IE isn't good at supporting anything scrolling tables. Editing a table in this way is rarely a good idea in any case. You can have one table with your TH wrapped in a div, then the rest of your info in another table, with another div with overflow auto
Another example.
It's not perfect as you have a lot on HTML visual attributes, you should get rid of those and use CSS only. But this is the basic functionality, it should work in all browsers.
Surround the table with divs with outer and then innera..check the css
.outer {
position:relative;
padding:4em 0 3em 0;
width:54em;
background:bottom;
margin:0 auto 3em auto;
}
.innera {
overflow:auto;
width:54em;
height:9.6em;
background:#eee;
border:2px gray;
}
.outer thead tr {
position:absolute;
top:2em;
height:1.5em;
left:0;
}
.outer th, .outer td {
width:10em;
text-align:left;
I tested the code and it is working. Tested in IE 6.0,7.0 ++ .The code is from internet:-)