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;
}
Related
I'm showing a member who has a higher rank. Based on that, I have to show the user image along with the username.
but I'm not able to align the image and text efficiently..The problem is some username consists of a longer number of characters. As a result, the username showed in a zig-zag position..
so far, I've tried
<table style="width: 100%; table-layout: fixed" class="table table-striped text-center">
<thead class='bg-dark' style='background-color: 3658DE'>
<tr>
<th><img src='../assets/img/gold.png'/>Rank</th>
<th><i class='fa fa-user mr-1' style='color: #F4B806'></i>Members</th>
</tr>
<tr>
<td>
1
</td>
<td>
<div class='text-center'>
<img src='images' alt='user dp' class=' img-fluid rounded-circle' style='height: 30px; width: 30px;' />
<span class='mr-1 '>#$username</span>
</div>
<td>
</tr>
</thead>
<tbody>
Expected output:
Rank Member
1 image Dravid
2 image Richard Nixon
3 image GrahamBell
4 image Mark twains
Output's getting:
Rank Member
1 image Dravid
2 image RichardNixon
3 image GrahamBell
4 image Mark twains
img {margin-right:10px;};
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Rank</th>
<th scope="col">Member</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td><img src="image"/>member</td>
</tr>
<tr>
<th scope="row">2</th>
<td><img src="image"/>anotherMember</td>
</tr>
<tr>
<th scope="row">3</th>
<td><img src="image"/>oneMoreMember</td>
</tr>
</tbody>
</table>
Please check your table markup, it doesn't seems to have any data in <tbody> . If you have to show the user image before the username place the <img/> inside the <td> tag just before the name of the member(in your case username). This will give you the alignment as per your need, no matter how long is the username provided that the size(mostly width) of all the images is same. I have included little CSS just to provide some space between all images and usernames. Also make sure this space remains constant for all images, if you wish to include it.
Your problem is that you are using the text-center class on each <tr>'s second <td> (to display the username). That's because your those are centered accordingly resulting in this bug:
In order to solve this you have to replace it with text-left like in this example. The same for the second <th>. In order to place your item more to the right, apply a padding-left, e.g., by adding Bootstrap's pl-5:
<table style="width: 100%; table-layout: fixed" class="table table-striped text-center">
<thead class='bg-dark' style='background-color: 3658DE'>
<tr>
<th><img src='https://via.placeholder.com/25'/> Rank</th>
<th class="text-left pl-5"><i class='fa fa-user mr-1' style='color: #F4B806'></i>Members</th>
</tr>
</thead>
<tbody>
<tr>
<td>
1
</td>
<td>
<div class='text-left pl-5'>
<img src='https://via.placeholder.com/150' alt='user dp' class='img-fluid rounded-circle' style='height: 30px; width: 30px;' />
<span class='mr-1 '>Dravid</span>
</div>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
<div class='text-left pl-5'>
<img src='https://via.placeholder.com/150' alt='user dp' class='img-fluid rounded-circle' style='height: 30px; width: 30px;' />
<span class='mr-1 '>RichardNixon</span>
</div>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
<div class='text-left pl-5'>
<img src='https://via.placeholder.com/150' alt='user dp' class='img-fluid rounded-circle' style='height: 30px; width: 30px;' />
<span class='mr-1 '>GrahamBell</span>
</div>
</td>
</tr>
</tbody>
</table>
You can find a running fiddle here, which produces the following table:
I would like to remove the white space between Table Title and Sub Titles.
Also Sub Title "Sub1" together with the icon should be left-aligned within the cell
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-3">
<div class="mdc-card p-0">
<h6 class="card-title">Table title</h6>
<div class="table-responsive">
<table class="table">
<thead bgcolor="#aed581">
<tr>
<th>
<span class="text-left">Sub1</span>
<span class="material-icons refresh-icon">refresh</span>
</th>
<th>Sub2</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left">A</td>
<td>18.5%</td>
</tr>
<tr>
<td class="text-left">B</td>
<td>16.3%</td>
</tr>
<tr>
<td class="text-left">V</td>
<td>15.5%</td>
</tr>
</table>
</div>
</div>
</div>
You need do with some css for remove that space
apply this css into ur css file margin-bottom: 0; will remove space from table-responsive and card title
.card-title{
background-color: #aed581;
padding: 15px;
font-weight: bold;
margin-bottom: 0;
}
.fa-repeat{
color: lightgray;
cursor: pointer;
}
and for icon i used font-awesome icon here is the CDN link
https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css
Here is the HTML
<div class="mdc-layout-grid__cell stretch-card mdc-layout-grid__cell--span-3">
<div class="mdc-card p-0">
<h6 class="card-title">Table title</h6>
<div class="table-responsive">
<table class="table">
<thead bgcolor="#aed581">
<tr>
<th>
<i class="fa fa-repeat"></i>
Sub1
<!-- <span class="material-icons refresh-icon">refresh</span> -->
</th>
<th>Sub2</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-left">A</td>
<td>18.5%</td>
</tr>
<tr>
<td>B</td>
<td>16.3%</td>
</tr>
<tr>
<td>V</td>
<td>15.5%</td>
</tr>
</table>
</div>
</div>
</div>
You can edit or preview code here
Hello I am designing a page and my client wants an image to appear when you hover over one of the rows in a table. We don't want the image to appear inside the table, just floating above it. I am not sure how much code I should supply here:
<div class="tg-wrap"><table id="tg-VGIE9" class="tg">
<tr>
<th class="tg-yw4l">Item #</th>
<th class="tg-yw4l">Product Family</th>
<th class="tg-yw4l">Item Description</th>
<th class="tg-yw4l">Price</th>
</tr>
<tr>
<td class="tg-yw4l">161129-1</td>
<td class="tg-yw4l">Accessory</td>
<td class="tg-yw4l">3010-0289FG, CI-3 CABLE ASSEMBLY</td>
<td class="tg-yw4l">$189.94</td>
</tr>
</table></div>
So when you rollover anything from 161129-1 to the price, the image would appear above.
Thank you for your help!
Using CSS to make something appear above the thing you're hovering, since you can't traverse up the DOM in CSS and can only traverse down, you can use flexbox with order to visually re-position things while still keeping the element after the element you're hovering.
But if you're hovering over one thing, and you want something that came before that thing to be displayed on hover, javascript is probably a better solution.
* {margin:0;}
tbody {
display: flex;
flex-direction: column;
}
.img {
display: none;
order: -1;
}
tr:hover + .img, tr:hover {
display: flex;
}
<div class="tg-wrap">
<table id="tg-VGIE9" class="tg">
<tbody>
<tr>
<th class="tg-yw4l">Item #</th>
<th class="tg-yw4l">Product Family</th>
<th class="tg-yw4l">Item Description</th>
<th class="tg-yw4l">Price</th>
</tr>
<tr>
<td class="tg-yw4l">161129-1</td>
<td class="tg-yw4l">Accessory</td>
<td class="tg-yw4l">3010-0289FG, CI-3 CABLE ASSEMBLY</td>
<td class="tg-yw4l">$189.94</td>
</tr>
<tr class="img">
<td colspan="4">
<figure>
<img src="https://futurism.com/wp-content/uploads/2015/11/neildegrassetyson.jpg">
</figure>
</td>
</tr>
<tr>
<td class="tg-yw4l">161129-1</td>
<td class="tg-yw4l">Accessory</td>
<td class="tg-yw4l">3010-0289FG, CI-3 CABLE ASSEMBLY</td>
<td class="tg-yw4l">$189.94</td>
</tr>
<tr class="img">
<td colspan="4">
<figure>
<img src="http://kenwheeler.github.io/slick/img/fonz1.png">
</figure>
</td>
</tr>
</tbody>
</table>
</div>
I need to set a link on a picture. I have to set it up in tables, which I did. But I cannot understand why the picture is linking in full width. That means the background color is also a link. That link should only be on the picture.
If it was a div tag it could be solved with a wrapper, but I do not know how to solve that within tables?
My Example
This is my code:
<body>
<table class="wrapper" align="center">
<tr>
<td class="wrapper-inner">
<!-- Row 1 -->
<table class="row collapse" >
<tbody>
<tr>
<th class="small-12 large-12 columns first">
<table>
<tr>
<th>
<img src="http://3.bp.blogspot.com/-Z4vZ7AsD6Bc/T_PNRK_9f2I/AAAAAAAAAH4/t3UZ3BQyqdE/s1600/shutterstock.jpg" alt="test" align="center" class="float-center" >
</th>
<th class="expander"></th>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
<!-- Row 2 -->
<table class="row collapse bgcolor--blue">
<tbody>
<tr>
<th class="small-12 large-12 columns">
<table>
<tr>
<th>
<img src="http://24.media.tumblr.com/7a40daf7853d830815fb83f79752e94a/tumblr_mz2izkaidT1rfn9zxo4_500.png" alt="Fashion news" align="center" class="float-center">
</th>
<th class="expander"></th>
</tr>
</table>
</th>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</body>
I didn't notice this should happen. Try this CSS :
th {
text-align: center;
}
th a {
display: inline-block;
}
edit using #SpencerMay comment
I have a table where I have successfully set up the body to scroll, and leave the header alone, but this now appears to be causing problems with column widths:
One has to specify the widths of columns in the tbody to be the same as the ones in the thead, else the browser decides to do things how it thinks it should be done, ie: wrong.
however, the browser (and this is consistent across the three recognised mainstream browsers - ie, firefox and chrome) still seems to want to vary the size of my columns.
here is a code sample:
CSS:
<style>
#divPersonalTables tbody:nth-child(2) {max-height: 350px; overflow-y: scroll; overflow-x: hidden}
.tdTextColumn { width: 200px }
.tdCheckColumn { width: 86px }
</style>
HTML:
<div style="display: flex" id="divPersonalTables">
<table id='tblTables' style="display: inline-block; width: 500px">
<thead>
<tr>
<th class="tdTextColumn">Forename</th>
<th class="tdTextColumn">Surname</th>
<th class="tdCheckColumn">Current</th>
<th style="width: 14px"></th>
</tr>
</thead>
<tbody style="display: block">
<tr>
<td style="display: none"></td>
<td class="tdTextColumn"><input type="text" /></td>
<td class="tdTextColumn"><input type="text" /></td>
<td class="tdCheckColumn"><input type="checkbox" /></td>
</tr>
</tbody>
</table>
</div>
The scrolling body style is applied to all tbody elements contained within that div, as there are two - one omitted here for conciseness.
So in summary: how can I make sure the browser is setting the columns to the widths I think it should be ?
The order of your columns does not match.
Put your hidden column to the right and you should be set.
<div style="display: flex" id="divPersonalTables">
<table id='tblTables' style="display: inline-block; width: 500px">
<thead>
<tr>
<th class="tdTextColumn">Forename</th>
<th class="tdTextColumn">Surname</th>
<th class="tdCheckColumn">Current</th>
<th style="width: 14px"></th>
</tr>
</thead>
<tbody style="display: block">
<tr>
<td class="tdTextColumn"><input type="text" /></td>
<td class="tdTextColumn"><input type="text" /></td>
<td class="tdCheckColumn"><input type="checkbox" /></td>
<td style="display: none"></td>
</tr>
</tbody>
</table>
btw: Why do you set <td style="display: none"></td> ?