I am using materialize css, even if I add lot of columns, they adjusts themselves according to the size of the page. I want to make them horizontally scrollable. How to make it scrollable? Here is my table code:
<table class="striped centered responsive-table">
<thead>
<tr>
<th></th>
<th>USN</th>
<th>Name</th>
<th>Department</th>
<th>Address</th>
<th>Student's Phone</th>
<th>Parent's Phone</th>
<th>Student's Email</th>
<th>Parent's Email</th>
</tr>
</thead>
<tbody>
<?php
$result=$db->query($semqy);
$i=0;
while($semdata=$result->fetch_assoc())
{
echo "<tr><td>
<input type='checkbox' id='chkbx$i' name='chkbx$i'/>
<label for='chkbx$i'></label>
</td><td>".$semdata['USN']."</td><td>".$semdata['Name']."</td><td>".$semdata['Dept']."</td><td>".$semdata['Address']."</td><td>".$semdata['Sphone']."</td><td>".$semdata['Pphone']."</td><td>".$semdata['Semail']."</td><td>".$semdata['Pemail']."</td></tr>";
$i++;
}
?>
<tr><td>Send Email</td></tr>
<tr>
<td>Student</td><td>
<input type="checkbox" id="schkbx" name="schkbx"/><label for="schkbx"></label></td>
<td>Parent</td><td><input type="checkbox" id="pchkbx" name="pchkbx"/><label for="pchkbx"></label></td>
</tr>
</tbody>
</table>
A proposed way to go around this is to wrap your table within a who's function is going to be a container and an overflow window.
<div class='table-wrapper'>
<!-- Table Content goes here -->
</div>
With table wrapper in place, you can hide the exceeding content in any overflow you wish. You can check the overflow properties and what they do here: https://developer.mozilla.org/en/docs/Web/CSS/overflow?v=example
For your need, since it's horizontal, we'd want to use the property overflow-x and to force a scroll bar to the division, we would add scroll to it.
Of course, you will have to define the max-width of your wrapper div to the desired measure. Additionnaly, you will ahve to force a size on your table cell to make them take the appropriate space you desire.
Also, very importantly, you will need to set the properties of your table as such:
#tableName {
width: 100%;
table-layout: fixed;
}
This will prevent your table from resizing with the container size.
You can look at an example here:
https://codepen.io/DrSandwich/pen/ZKyvoP
Related
I have some problem with table-responsive class because it is generating scroll on y axis when it is not indicated on the css.
Here is picture of the problem and I also replicated the bug
<div id="app">
<div class="container">
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>N°</th>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>
<multiselect
v-model="value"
:options="options"
:multiple="true"
track-by="library"
:custom-label="customLabel"
>
</multiselect>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
https://jsfiddle.net/ggalvez92/3d8h4sqy/
I have tried to put overflow-y: visible but nothing seems to work.
I would appreciate if someone can help me to fix it.
If we change:
.multiselect__content-wrapper { display: contents; }
It can grow inside the table cell but affecting the table height.
Or if you use:
.table-responsive { overflow: unset; }
It can grow outside of the cell without affecting the table height.
So to fix the dropdown outside the table cell and keep overflow on the .table-responsive I don't believe this can be fixed CSS only. JavaScript solutions have been reported to:
add some bottom padding (only applicable when the dropdowns are on the last rows)
append the dropdown to the body and recalculate the offset
add position: fixed when open, and recalculate width, left and right offset
So, after some struggle with Vue (first time) I've found a solution that might suit your needs. This solution uses the position: fixed as mentioned earlier.
repositionDropdown (id){
const el = document.getElementById(id);
const parent = el.closest('.multiselect');
const content = parent.querySelector('.multiselect__content-wrapper');
const { top, height, left } = parent.getBoundingClientRect();
content.style.width = `${parent.clientWidth}px`;
content.style.position = 'fixed';
content.style.bottom = 'auto';
content.style.top = `${top + height}px`;
content.style.left = `${left}px`;
}
By adding the #open event to the setup it also requires an :id. For some reason this id needs to be numeric, I don't know why at this point. It might need some extra finetuning but at least it solves one of the bigger issues.
DEMO
I have three entities in a row, currently I use table to display them:
<table>
<tbody>
<tr>
<td id='td1'>some text</td>
<td id='td2' style='width:600px;'>some text</td>
<td id='td3'>some text</td>
</tr>
</tbody>
</table>
What I need is to resize left and right cells simultaneously when browser resizes. I wonder if it is possible without JS.
I have even tried CSS resize which apparently does not work in IE, played with widths of the cells, but still without any success. I am totally a newbie in CSS.
Is it even possible? Thanks in advance.
Can't verify since I'm on a mobile but have you tried....
<table>
<colgroup>
<col class="first" />
<col />
<col class="last" />
</colgroup>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Then use the col.first and col.last classes to style them with css.
W3C: http://www.w3.org/TR/html-markup/col.html
Oh, and, remove all the css from your html. Having css inline will make the document completely unmaintainable through css files. And remove the IDs also from td:s and always use " to quote html attribute values.
You can also try to add:
table {
table-layout: fixed;
}
To prevent the browser from calculating the initial width of each cell according to their contents and give them all initially an equal width. (height will still expand according to content.) Then override certain columns with css.
try this css
table{
width:100%;
}
it works.
I'm writing an angular email app and have used bootstrap tables in my mail template.
The body of the message is large and I would like to limit this to be just a single line, something similar to how gmail does it. Right now, my cell auto sizes which increases the size of the overall row. I used a couple of angular filters to limit the characters but I don't think that's all that Gmail is doing. There is some sort of an overflow hidden applied to the table row and also the height of each row is consistent.
How do I tweak my table css so that the row does not auto size when the cell data is a lot?
My HTML Code : http://pastebin.com/13jd9EfqI'm using the latest version of bootstrap css.
I know you'd want overflow: hidden and white-space: nowrap styles. If you want you can also add the text-overlow: ellipsis style for a nice effect. You can use table-layout: fixed to ignore the size of the contents of the cells and only look at the heading sizes, otherwise automatic column sizing can take into account the full width of the string (fiddle):
table.special { table-layout: fixed }
table.special th { width: 20% }
table.special th.content { width: 40% }
table.special td {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis
}
On your <tr> tags you should add style="width:[desired width]" so they don't resize, example:
<table class="table table-responsive table-striped table-hover">
<thead>
<tr>
<th style="width: 100px">MessageID</th>
<th style="width: 100px">Sender</th>
<th style="width: 100px">Content</th>
<th style="width: 100px">Date</th>
</tr>
</thead>
<tbody>
<tr ng-click="changeRoute('mail',message)" ng-repeat="message in mails.messages | filter:search | orderBy:sortField:reverse">
<td>ID</td>
<td>Sender</td>
<td>Content</td>
<td>Date</td>
</tr>
<tr ng-click="changeRoute('mail',message)" ng-repeat="message in mails.messages | filter:search | orderBy:sortField:reverse">
<td>ID</td>
<td>Sender</td>
<td>Content</td>
<td>Date</td>
</tr>
</tbody>
</table>
You can change the text of the <td> tags and it won't resize. You might want to add a padding to the left on your <td> tags so they are more 'inline' with the <tr> tag's text. DEMO
I have a div with a small width and an overflow visible. I have inside a larger table with only one cell and a text inside:
<div style="overflow:visible;width:0px;">
<table>
<tr>
<td style="border:solid">
A small text with spaces...
</td>
</tr>
</table>
</div>
I would like the width of the table to be set automotically as the text width but without breaking line. i.e. I would like to have the same result I would have if I writed only:
<table>
<tr>
<td style="border:solid">
A small text with spaces...
</td>
</tr>
</table>
How can I set the table to not be "of minimum width" without specifying a precise witdh?
I think your answer is here: Object larger than outside div
It uses the position absolute to remove the stipulations of the containers surrounding it. The one issue then is positioning, but You can fix that with setting the left and top CSS rules.
jsfiddle example
<div style="overflow:visible;width:0px;">
<table>
<tr>
<td style="border:solid;position:absolute;">
A small text with spaces...
</td>
</tr>
</table>
</div>
<div style="overflow:visible;width:0px;padding-top:30px;">
<table>
<tr>
<td style="border:solid;white-space:nowrap;">
A small text with spaces...
</td>
</tr>
</table>
</div>
EDIT
As said in a comment above by "insertusernamehere": "white-space:nowrap;" works as well.
NOTE:
Tables are not the best thing to use. Use DIV's and set the `"float:left/right;" CSS style so that they mimic tables. It is easier to code (for me at least, it takes some getting used to at first.) but it is much more browser friendly and you have more room to play in.
In responsive table design to refer I got this link jsfiddle.net/n4rUG/27/
This gives me below output:
Now I want to align title to left and its value to right
means it need to look aligned properly
How to do this?
The text-align: right doesn't work for your tds because it's overridden by the Bootstrap style with higher specifity. The quickest solution is just to add !important. Also, I'd suggest to make the labels floating to left (see modified fiddle):
td {
...
text-align: right !important;
overflow: hidden; /* for containg floats */
}
td:before {
...
float:left;
}
Your JSFiddle is different then the image in your post.
Refering to your image, you could make it like this, using colspan to set your colums width:
<table>
<colgroup>
<col width="100px" />
<col width="200px" />
</colgroup>
<tr>
<td>title</td>
<td>value</td>
</tr>
<tr>
<td>title</td>
<td>value</td>
</tr>
...
</table>
As for your JSFiddle, you have 5 <th>'s and 6 <td>'s. Which is possible, however, one of the <th> should cover two <td>'s, you can make that by using this:
<th colspan="2">Title</th>