Problems displaying a table on mobile version of my site - css

I've been trying to fix this issue for 10 days now and still i couldn't find any solution.
I have a table that shows perfectly on desktop version but on mobile it gets out of the page area, i tried also #media screen max width 600px to modify the size of the table and overflow hidden but still not working, i will paste the code below:
<style type="text/css">
table {
border-collapse: collapse;
width: 100%;
}
td {
border: 1px solid #d3d3d3;
text-align: center;
white-space: nowrap;
}
th {
background-color: #0288D1;
border: 2px solid #d3d3d3;
text-align: center;
font-size: large;
color: white;
text-transform: uppercase;
}
</style>
<table>
<thead>
<tr>
<th colspan="4" style="background-color:#0277BD"><strong>Some Text Here<strong></th></tr>
<tr>
<th><strong>Some Text Here</strong></th>
<th><strong>Some Text Here</strong></th>
<th><strong>Some Text Here</strong></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a rel="nofollow" target="_blank" href="https://somesite.com/play"><img width="200" height="80" src="https://somesite.com/image.png" alt="Some Text Here"></a>
</td>
<td><strong><font color="green">Some Text Here</font></strong></td>
<td>Some Text Here</td>
<td>
<div>
<button class="playblock" style="display:block;width:150px;height:50px;background-color:#4CAF50;margin-bottom:5px;color:white;font-size:20px;cursor:pointer;text-align:center;" onmouseover="this.style.backgroundColor='green'" onMouseOut="this.style.backgroundColor='#4CAF50'" onclick="window.location.href = 'https://somesitehere.com/play';">PLAY</button>
</div>
<div>
<button class="reviewblock" style="display:block;width:150px;height:50px;background-color:#EB9C12;color:white;font-size:20px;cursor:pointer;text-align:center;" onmouseover="this.style.backgroundColor='orange'" onMouseOut="this.style.backgroundColor='#EB9C12'" onclick="window.location.href = 'https://somesitehere.com/see/';">REVIEW</button>
</div>
</td>
</tr>

This is a common problem with tables on mobile. It is not clear if you are using the table for layout or if you will have more rows of data with Play and Review links.
If you are using it for layout, I would suggest exploring a flexbox layout instead.
If you are planning to have more rows in the table you could wrap the table in a <div> with max-width: 100%; overflow: auto; that would allow the div/table to horizontally scroll but not otherwise affect the layout of the page. Pair this with reduced font-size on smaller screens and, IMO, you get a pretty usable table on mobile.
There are a few methods for modifying how a table is rendered on small screens by using a data attribute (like data-title) on the <td> and <th> that duplicate the column heading so that on small screens you can pull the data attribute using a ::before pseudo element like td::before { content: attr(data-title); } and tell your table elements to all be display: block; and styling them kinda like each row is it's own table.
Here is an example from CSS Tricks: https://css-tricks.com/responsive-data-tables/

You have to decide what it should look like on mobile. The simple fix is to set a min-width on the table but this might make things to small on mobile. You should also be using a media query to make the buttons smaller, they are very large.
table { min-width: 500px; }

Add a container element with overflow-x:auto around the <table>, for example:
<div style="overflow-x:auto;">
<table>
...
</table>
</div>
This table will display a horizontal scroll bar if the screen is too small to display the full content.

Thanks for all your feedback.
I fixed it myself after some testing using:
#media only screen and (max-width: 800px) { ... }

Related

how to make responsive table with bootstrap

need help to make table responsive.
On this size everything is ok:
but when screen size is reduced im getting smth like this:
table is displayed on col-md-7:
<div class="row">
<div class="col-md-7">
<div class="ritekhela-fancy-title-two">
<h2>Turnyrinė lentelė</h2>
</div>
<div class="rs-point-table sec-spacer">
<div class="tab-content">
<table>
<tr>
<td>Vieta</td>
<td class="team-name">Komanda</td>
<td>Sužaista</td>
<td>Perg.</td>
<td>Lyg.</td>
<td>Laim.</td>
<td>Įm.</td>
<td>Pr.</td>
<td>+/-</td>
<td>Taškai</td>
</tr>
<tr>
<td>01</td>
<td class="team-name">Banani FC</td>
<td>60</td>
<td>35</td>
<td>08</td>
<td>16</td>
<td>02</td>
<td>04</td>
<td>11</td>
<td>95</td>
</tr>
</table>
</div>
</div>
</div>
EDITED:
If i trying to add max and min width, marked place is reducing too much:
I've had a look into your second example.
the troubling part is obviously your title bar, whose elements are inside the class ritekhela-fancy-title-two
And you have a wrapping div around this class, named row, this div needs to get set to adapt its width to the nested content.
Since fit-content is experimental and not available at all browsers, you'll need set width to auto and make it behave as an inline block
Then you must set the width of your ritekhela-fancy-title-two class to auto and remove the float:left, or set it to float:none and it will neither overflow on larger screens or not expand to the width of table on smaller screens.
that's it, check the fiddle with above changes implemented
these are the two css styles which were changed/added:
.row {
width: fit-content; /*works with Chrome, but not with FF*/
width: auto;
display: inline-block;
}
.ritekhela-fancy-title-two {
float: none;
width: auto;
padding: 12px 20px 12px 60px;
border-top: 7px solid;
background: url(/css/images/transparent-pattren.png);
position: relative;
margin-top: 30px;
background-color: #6c757d;
}
edit: as above changes also affect the lower title bars, which is easy to correct, adding some height to the second row:
.ec-nextmatch {
border: 1px solid #f3f3f3;
border-top: none;
background-color: #fff;
margin-bottom: 60px;
float:none;
height:90px;
width:auto;
}
also remove .ec-nextmatch from this css, so it looks now:
.ec-team-matches, .ec-match-countdown, .ec-match-countdown .countdown-row, .ec-ticket-button {
float: left;
width: 100%;
}
If you want to avoid the hassle of reducing font sizes, table cells widths, etc. I would recommend using the Bootstrap responsive table utility, basically makes the table scroll horizontally. Can be achieved like so...
...
<div class="tab-content table-responsive">
<table class="table">
...
</table>
</div>
...

CSS bottom Border Issue

I seem to be having issues with the either the border, or the box shadow appearing on my site.
If need be I will post the CSS for the areas that have the borders applied but it may be easier to just link you to my site: http://w11.zetaboards.com/GamesAndAnime/index/
Please remove below tr
<tr>
<td colspan="6" class="c_foot"></td>
</tr>
And add padding-bottom:10px to table (css.css line no:31) like below
table {
clear: both;
width: 100%;
padding-bottom: 10px;
}

Floating button inside caption

I am trying to create a button inside the caption of a table. It works in both Firefox and Chrome, but not IE 7 (The most used browser for my userbase). IE 7 creates the button on a new line below instead of floating it to the right.
Here is the (simplified) html
<table>
<caption>
Versions
<button class="inline-button">Add</button>
</caption>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<tr>
<td>10.0</td>
<td>Oompa-loompa</td>
</tr>
<tr>
<td>10.0</td>
<td>Oompa-loompa</td>
</tr>
</table>
Here is the css:
button.inline-button {
float: right;
border: 1px solid gray;
margin: 0;
}
table { width: 300px; }
caption { background: #ddd; }
As is usual (for IE7) one simple solution is to switch the order of the text and the button:
<caption>
<button class="inline-button">Add</button>
Versions
</caption>
http://jsfiddle.net/hgNdK/
If you float: left; the "Versions" bit, it works sensibly in IE6 and IE7. I also set display: inline; on the button, because you are trying to make it display in-line. It shouldn't make any difference because of the floating, but it more semantically correct, and it may help in certain browsers.
Here's a jsFiddle demonstrating the solution.

Align contents of DIV always on one line

I have the following :
HTML
<th class="sort">
<div>
<div class="sort"></div>Last Name
</div>
</th>
css:
table.tablesorter thead th.sort
{
padding:0;
}
table.tablesorter thead th div.sort
{
margin:0;
width:15px;
height:30px;
float:left;
background: url("/Content/images/admin/sort.png") no-repeat;
background-position: 0px center;
cursor:pointer;
}
table.tablesorter thead tr th.sort a
{
cursor:pointer;
color:inherit;
vertical-align:middle;
float: left;
padding-top: 7px;
}
I want to display inner and inside vertically aligned middle and always on ONE line so that when a browser window is resized (small) it will not break and will not more underneath inner (which is what is happening now).
thanks
use the "display inline" command...
<div style="display:inline;float left;">First name</div>
<div style="display:inline;float right;">Last name</div>
Its not clear to me what "inner" and "inside" youre referring to (you mught want to update and elaborate a bit, as well as post the complete markup for the table) but it sounds like you basically want everything in the th to be in one continuous line regardless of avialable space. You can turn off the text from wrapping with whitespace: nowrap;. However your content is going to overflow the th because thats how table cells work, so you need to set overflow: hidden on something that wraps the text. Unless yo need more than one elemment inside the cells you dont need the float.
The markup might look like this:
<thead>
<th><div class="clip sort">First Name</th>
<th><div class="clip sort">Last Name</th>
</thead>
Whith the css like so:
.clip {width: 100%; overflow: hidden; whitespace: nowrap;}
th {vertical-align: middle; height: 30px;}

IE7: How to make TD float?

I want a set of <td>s to float left in IE7. They should break onto the next line if the window is too small.
CSS
table {
width: 100%;
}
td {
border: 1px solid red;
}
tr.f td {
width: 500px;
float: left;
}
HTML:
<table>
<tr class="f">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
This works in IE8 and Firefox, but not in IE7. What am I doing wrong?
Page rendering mode is "IE7 (Quirks)" or "IE7 (Standards)". I'm trying with IE8, though, trusting that IE7 rendering mode is what it says. "IE8 Compatibility View" is failing as well, only "IE8 Standards" gets it right.
I don't think this is possible the way you want.
When you apply the float to td elements [in FF/IE8[ they become anonymous table objects as per the CSS 2.1 spec. Essentially, they're no longer table cells, and these anonymous objects have a display type that is floatable.
IE7 doesn't follow this part of the spec, in fact, the display type of the cells cannot be altered at all, and objects with a display type of table-cell can't be floated.
If you absolutely need to use a table (instead of a ul/li) could you do something like this instead?
<style type="text/css" media="screen">`
table {
width: 100%;
}
.f {
border: 1px solid red;
float: left;
height: 10px;
width: 500px;
}
</style>
<table summary="yes">
<tr><td>
<span class="f">1</span>
<span class="f">2</span>
<span class="f">3</span>
</td></tr>
</table>
My best guess: IE7 and below have stricter table models and don't allow you to change the flow of table elements.

Resources