So my text is "falling" out of my page at certain sizes, how do I stop this?
I have Googled and tried many things to no avail.
If you check out my screenshot u can see what I mean, and the code that is the victim of this is below as well.
Thanks in advance!
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%
</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
One way is to use overflow: scroll on the problematic div, so that it becomes scrollable:
.container > div {
overflow: scroll;
background-color: #fff;
}
body {
background-color: pink;
}
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor"> <div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
Alternatively, you can use some Javascript to check the current screen width, and then resize content appropriately using CSS's transform: scale(). In the example below I used jQuery for brevity, but this can sure be done using plain JS. Two things to note here:
The content should resize as the browser window is resized;
When using transform: scale, it is best to also set the transform-origin of the div to top-left so that the div does not "move around" as it is scaled.
$(document).ready(function() {
resizeTable();
});
$(window).on("resize", function() {
resizeTable();
});
function resizeTable() {
var width = $(document).width();
// if width / 1500 is greater than 1, set scale to 1
// (i.e. do not zoom in stuff if the screen is very large)
// here 1500 is only an example, you can set the number to whatever you see fit
scale = Math.min(width / 1500, 1);
$(".container table").css("transform", `scale(${scale})`);
}
.container > div {
overflow: scroll;
background-color: #fff;
}
.container table {
transform-origin: left top;
}
body {
background-color: pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="shadow p-3 mb-5 bg-white rounded">
<table class="table">
<thead>
<tr>
<th scope="col" >CRN</th>
<th scope="col">Subject</th>
<th scope="col">Course</th>
<th scope="col">Credits</th>
<th scope="col">Title</th>
<th scope="col">Days</th>
<th scope="col">Times</th>
<th scope="col">Instructor</th>
<th scope="col">Attribute</th>
<th scope="col">Professor Difficulty</th>
<th scope="col">Professor Rating</th>
<th scope="col">Would Take Again</th>
</tr>
</thead>
<tbody>
{% for row in all_data %}
<tr>
<th>{{row['crn']}}</th>
<td><strong>{{row['subj']}}</strong></td>
<td >{{row['crse']}}</td>
<td>{{row['cred']}}</td>
<td>{{row['title']}}</td>
<td>{{row['days']}}</td>
<td>{{row['time']}}</td>
<td>{{row['instr']}}</td>
<td>{{row['Attr']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor"> <div class="progress">
<div class="progress-bar" role="progressbar" style="width: {{row['profDiff']}}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{row['profDiff']}}%</div>
</div>
</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profRating']}}</td>
<td data-bs-toggle="tooltip" data-bs-placement="top" title="Information Taken From RateMyProfessor">{{row['profWouldTakeAgain']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</body>
However, this second approach is not optimal for very small screens, e.g. mobile phones, as text will become way too small to read. So, such small screens should ideally be handled separately using CSS media queries.
Related
I am using bootstrap 5.
I have a table and I need to display four images side by side. This seems to work on a large screen:
However, on a phone the images are shrunken and no longer visible:
How can I force the images to remain at least 16px even on phone screens? The table will have a horizontal scroll but that is ok.
Is there a better way to display 4 img tags in one td and force all of them to be on the same line? The only way I found to do it is by putting them in row and col divs.
Code:
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">Username</th>
<th scope="col">Match Predictions Made</th>
<th scope="col">Winner</th>
<th scope="col">Finals</th>
<th scope="col">Top 4</th>
<th scope="col">Points</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Marcipanas</th>
<td>5/36</td>
<td><img src="assets/flags/be.svg" class=" float-start flag-img" alt="be"></td>
<td>
<div class="row">
<div class="col"><img src="assets/flags/it.svg" class="flag-img" alt="it"></div>
<div class="col"><img src="assets/flags/cz.svg" class="flag-img" alt="cz"></div>
</div>
</td>
<td>
<div class="row">
<div class="col"><img src="assets/flags/be.svg" class="flag-img" alt="be"></div>
<div class="col"><img src="assets/flags/dk.svg" class="flag-img" alt="dk"></div>
<div class="col"><img src="assets/flags/fi.svg" class="flag-img" alt="fi"></div>
<div class="col"><img src="assets/flags/ru.svg" class="flag-img" alt="ru"></div>
</div>
</td>
<td>0</td>
</tr>
<tr>
<th scope="row">test3</th>
<td>0/36</td>
<td><img src="assets/flags/it.svg" class=" float-start flag-img" alt="it"></td>
<td class="text-muted">No prediction</td>
<td class="text-muted">No prediction</td>
<td>0</td>
</tr>
<tr>
<th scope="row">testing1</th>
<td>1/36</td>
<td class="text-muted">No prediction</td>
<td class="text-muted">No prediction</td>
<td class="text-muted">No prediction</td>
<td>0</td>
</tr>
<tr>
<th scope="row">test2</th>
<td>0/36</td>
<td class="text-muted">No prediction</td>
<td class="text-muted">No prediction</td>
<td class="text-muted">No prediction</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
EDIT
As John suggested bellow I tried to add nowrap instead of using row-col but that seems to have forced everything into separate lines.
Code:
<td>
<div class="no-wrap">
<img src="assets/flags/be.svg" class="flag-img" alt="be">
<img src="assets/flags/dk.svg" class="flag-img" alt="dk">
<img src="assets/flags/fi.svg" class="flag-img" alt="fi">
<img src="assets/flags/ru.svg" class="flag-img" alt="ru">
</div>
</td>
css:
.flag-img {
max-height: 32px;
min-height: 16px;
min-width: 16px;
}
.no-wrap {
flex-wrap: nowrap !important;
}
Image of results:
So bootstrap defaults .row to have flex-wrap: wrap; You can add this to your CSS for force it to stop wrapping:
.row {
flex-wrap: nowrap !important;
}
Though I'd might consider adding a new class to each row with the images and calling that class instead of just outright .row incase there are areas where you want it to wrap. But this code will work.
As for the shrinking issue, if you want your pictures to never be smaller than 16px you can add this code to your CSS:
.flag-img {
min-width: 16px;
}
My HTML table is getting more time to load when the row count is large. I have to load almost 50000 row table to the webpage. I just used basic HTML table. ASP.NET C#.
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Available Resistors In Stock</h3>
<!--
<input type="text" class="form-control pull-right" id="task-table-filter" data-action="filter" data-filters="#task-table" placeholder="Filter Resistors" />
-->
</div>
<table class="table table-hover" id="task-table">
<thead>
<tr>
<th class="center">#</th>
<th class="center">Resistor Type</th>
<th class="center">Resistor Value</th>
<th class="center">Ohm</th>
<th class="center">Location</th>
<th class="center">PL</th>
<th class="center">Place</th>
<th class="center">Category</th>
<th class="center">Quantity</th>
<th class="center">Part NO</th>
<th class="center">Description</th>
<th class="center">Active</th>
<th class="center">Edit</th>
</tr>
</thead>
<tbody>
#for (int i = 0; i < Model.Rows.Count; i++)
{
<tr class="center">
<td>#Model.Rows[i][0]</td>
<td>#Model.Rows[i][1]</td>
<td>#Model.Rows[i][2]</td>
<td>#Model.Rows[i][3]</td>
<td>#Model.Rows[i][4]</td>
<td>#Model.Rows[i][5]</td>
<td>#Model.Rows[i][6]</td>
<td>#Model.Rows[i][7]</td>
<td>#Model.Rows[i][8]</td>
<td>#Model.Rows[i][9]</td>
<td>#Model.Rows[i][10]</td>
<td>#Model.Rows[i][11]</td>
<td>
<a href="#Url.Action("StoreAddResistors", "Store",new {#id=#Model.Rows[i][0] } )">
<span class="glyphicon glyphicon-refresh"></span>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
Is there any way to reduce the loading time of the webpage?
try to split the page into several. Or is it possible to somehow connect several html documents to 1 page? I have no more idea
I am trying to make something like this in Bootstrap 4, setting the columns of table in pixels, with fixed values, forcing the horizontal scroll inside the card, but is not working. The columns don't have the size I want. The columns sizes are going to be same for all devices.
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table class="table-sm table-hover table-bordered text-center">
<thead>
<tr class="text-uppercase font-size-1">
<th width="500px" class="font-weight-medium"></th>
<th width="500px" class="font-weight-medium">produto</th>
<th width="500px" class="font-weight-medium">status</th>
<th width="500px" class="font-weight-medium">sku</th>
<th width="500px" class="font-weight-medium">preço</th>
<th width="500px" class="font-weight-medium">estoque</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
What am I doing wrong?
It does seem to be working here is the example code
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<table class="table-sm table-hover table-bordered text-center">
<thead>
<tr class="text-uppercase font-size-1">
<th style="width:100px" class="font-weight-medium">first</th>
<th style="width:200px" class="font-weight-medium">produto</th>
<th style="width:300px" class="font-weight-medium">status</th>
<th style="width:400px" class="font-weight-medium">sku</th>
<th style="width:500px" class="font-weight-medium">preço</th>
<th style="width:600px" class="font-weight-medium">estoque</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
you need to put correct inline styles tag
<th style="width:500px;">
I have found something unusual and was wondering if this is intentional behaviour and if there is a fix for this. I would ideally like to stay within bootstrap without having to specify specific widths.
I am using twitter bootstrap to format a table. However when there is a table with no data the column widths are different to a table with data, i.e. a body with rows.
I have created a jsFiddle to demo this. jsFiddle
Here is the html.
<div class="col-md-10 col-md-offset-1">
<div class="col-md-12 category-header"><span class="">Turbo</span></div>
<div class="col-md-12 no-padding">
<div class="table-responsive">
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="col-md-1">ISTB10768R</td>
<td class="col-md-3">REMANUFACTURED TURBO</td>
<td title="" class="col-md-3 text-center"></td>
<td class="col-md-2 text-center"></td>
<td class="col-md-1 text-center">
<i title="" data-placement="top" data-toggle="tooltip" class="fa fa-check amber black-tooltip" data-original-title="Less than three units in stock"></i>
</td>
<td class="col-md-1 text-right">£370.00</td>
<td class="col-md-1 text-right">
<span data-part-number="ISTB10768R" data-part-id="564" href="#" class="glyphicon glyphicon-shopping-cart add-to-cart-btn pink " title="Add To Cart ">Add</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-12 category-header"><span class="">Gear Boxes</span></div>
<div class="col-md-12 no-padding">
<div class="table-responsive">
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody/>
</table>
<div class="missing-parts">Please call the sales team for price and availability</div>
</div>
</div>
</div>
I am sorry but there is a problem in the code you provided(specifically in the second table), perhaps a typo. Which is causing the overflow.
Second table code you provided
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody/>
</table>
<div class="missing-parts">Please call the sales team for price and availability</div>
As you can see the <tbody/> is wrong. There is no starting <tbody> tag & the closing tag should be </tbody>. Also there the missing-parts in nowhere inside the table body. It is outside the table body and that's why the weird behavior.
I have provided the correct code below. Here is the updated Fiddle. Works fine now.
Corrected table code
<table class="table no-margin">
<thead>
<tr>
<th class="text-left col-md-1">Part No.</th>
<th class="text-left col-md-3">Description</th>
<th class="text-center col-md-3">Notes</th>
<th class="text-center col-md-2">Dates</th>
<th class="text-center col-md-1">Stock</th>
<th class="text-right col-md-1">RRP</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="missing-parts">Please call the sales team for price and availability</div>
</td>
</tr>
</tbody>
</table>
Very important thing to note here is that, even though you have not specified any number of data columns under the first <tr>, it automatically assigns the <td> values to its respective <th>s.
In other words. If you mention only one <td>, it will automatically become the data of the first header ie. "Part No.". Which also means the the width of the data takes the width of the header it corresponds to(just like the top table). Try adding another <td> inside the same table row, you will understand.
I want to do some things with my table but I think an image would sum it up as my english is not the best.
I want to first move the second button to the left. Just one button on each corner on top of my table.
And secondly I want to avoid my input textbox (or a button later) to resieze the whole row of the 2nd header.
Any help will do. I can't figure it out by myself.
Code
#Html.ActionLink("Reset filters", "Index",
null,
new { #class = "btn btn-success custom", #style = "color:white", #role = "button" }
)
<button class="btn btn-default custom" type="submit"><i class="glyphicon glyphicon-file"></i> Export to Excel</button>
<div style="padding-top: 12px"></div>
#using (Html.BeginForm("Index", "Materials", FormMethod.Get))
{
<div id="grid-list">
#{ Html.RenderPartial("_AjaxMaterialList", Model); }
</div>
}
Partial View Code
#using PagedList.Mvc <!--import this so we get our HTML Helper-->
#model IPagedList<eContentMVC.Models.Material>
<!-- import the included stylesheet for some (very basic) default styling -->
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
#*<div style="padding-top: 14px"></div>*#
<div class="panel panel-primary filterable" style="padding: 0px;
margin: 0px">
<div class="panel-heading">
<h3 class="panel-title">GDS eContent Master Data Service Tool</h3>
</div>
<table class="table table-bordered table-hover" style="width:100%">
<thead>
<tr>
<th class="centerAlign" style="width:14%">Brand</th>
<th class="centerAlign" style="width:25%">Category</th>
<th class="centerAlign" style="width:13%">Language</th>
<th class="centerAlign" style="width:7%">BCO</th>
<th class="centerAlign" style="width:9%">Material Cod</th>
<th class="centerAlign" style="width:7%">Derivation</th>
<th class="centerAlign" style="width:7%">Artwork</th>
<th class="centerAlign" style="width:7%">Delivery</th>
<th class="centerAlign" style="width:5%">Export</th>
</tr>
<tr>
<th class="centerAlign" style="height:4%"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
<th class="centerAlign"><input type="text" /></th>
</tr>
</thead>
<tbody>
// Content
</tbody>
</table>
</div>
<div class="centerAlign" style="padding: 0px; margin: -8px">
<!-- output a paging control that lets the user navigation to the previous page, next page, etc -->
#Html.PagedListPager(Model, page => Url.Action("Index", "Materials", new
{
brand_name = Request["brand_name"],
page
}))
</div>
This is the code for making the table looking the right way. For the button, use bootstrap's pull-right.
* {
box-sizing:border-box;
}
.mytable tr th{
height:42px;
}
.mytable input{
width:100%;
}
.mytable th:nth-of-type(1){
width:14%;
}
.mytable th:nth-of-type(2){
width:25%;
}
.mytable th:nth-of-type(3){
width:13%;
}
.mytable th:nth-of-type(4),.mytable th:nth-of-type(6),.mytable th:nth-of-type(7),.mytable th:nth-of-type(8){
width:7%;
}
.mytable th:nth-of-type(5){
width:9%;
}
.mytable th:nth-of-type(9){
width:5%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div class="panel panel-primary filterable">
<div class="panel-heading">
<h3 class="panel-title">GDS eContent Master Data Service Tool</h3>
</div>
<table class="table table-bordered table-hover mytable">
<thead>
<tr>
<th class="centerAlign">Brand</th>
<th class="centerAlign">Category</th>
<th class="centerAlign">Language</th>
<th class="centerAlign">BCO</th>
<th class="centerAlign">Material Cod</th>
<th class="centerAlign">Derivation</th>
<th class="centerAlign">Artwork</th>
<th class="centerAlign">Delivery</th>
<th class="centerAlign">Export</th>
</tr>
<tr>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
<th class="centerAlign">
<input type="text" />
</th>
</tr>
</thead>
</table>
</div>
<div class="centerAlign" style="padding: 0px; margin: -8px"></div>
If it helps, +1.
Without the real page i'm not sure, but:
To move the button on the right use bootstrap class pull-right.
To have every row at the same height. I think td have some padding inside. Put padding to 0 and fix the height in css
.table td {
height: 30px;
vertical-align: middle;
}
Or something like this