<table>
<tr>
<th>Chain</th>
<th>Chain</th>
<th>Country</th>
<th>City</th>
<th></th>
<th><img src="Star5a.png" alt=""></th>
<th><img src="Star4a.png" alt=""></th>
<th><img src="Star3a.png" alt=""></th>
</tr>
<?php
if($results)
{
// Throw them all in a while loop
while($prepare->fetch()) {
?>
At a certain media query I want to change the images. I’ve been scratching my head all day without coming to a decision about the best way to handle the php page (the css is obviously easy).
Should I create a new div to be display:none until I need it? but can I do it with a table? I suppose put the above table within a div and another with the different images inside another div.
I’m not sure about swapping the images out, but you might want to look at the structure and fix it up a little. This is an example of an HTML table structure from the Mozilla Developer Network. You’ll notice it uses the <thead> tag, which is missing from your own. I’d have thought you’d want to open up a <tbody> tag before you go into the loop for the data rows too.
There are two things that frighten me; tables and php. The idea of redoing the page, which I put together with a lot of Sitepoint help does not appeal to me, but… I will be looking at your suggestion as soon as I get this “small” problem out of the way: changing images at a lower screen width.
I’ve put the page in a temporary test page for you to see (It will be deleted soon). Enter Oxford as a query and after getting the results, narrow the page. I want it go all the way to below 300px and I’m having problems at about 330px. I have new smaller images that might do the trick.
If the current table closed before the php code, I would know what to do, but starting two divs that only close later after a lot of php, confuses me a bit,
I’m not sure where <div> tags come into it. I could understand them perhaps being wrapped around an entire table, but I’d not think they would be appropriate inside the table structure themselves. How do you think they would help in this situation?
I don’t think that duplicating the table is a good idea, if you do go down the route of duplication, I would do it only to the images, not the whole table:-
But there may be better options. The initial thought is the standard way of making responsive images, by allowing them to scale to fit their container. however if you need to use a totally different image, you will need something else.
In that case, the first thing to mind is the new picture element, it is for exactly this purpose. The only problem I see with that is your apparent need for legacy browser support.
Another option is to use a background image, that can be easily swapped with a query. The issue with that being the lack of content in the cell will affect semantics for screen readers and bot, as well as the cell size. So that approach would require some form of text/image replacement.
The primary problem that I see at the moment (before caffeine) is a dirth of effective use of the table elements. Too much padding inside the cells instead of using text-align:center, for example, and, as @SamA74 mentioned, you have not taken advantage of allowing the images to scale down at narrow widths. Making your table sufficiently fluid shouldn’t be a big deal. Unless dorked with, fluid is how tables behave quite naturally.
Recode the table. No need to create a duplicate with slightly smaller images.
the current page that is live works well . I decide to add an extra column for State to take into account that there must be two dozen Londons in the USA!.. and that has caused problems of width.
I spent a couple of days changing database tables and this files and it is such a little thing I would like to just finish it and have it done with,
However, the various replies in this thread have convinced me that I must THEN spend some time and change the tables to make them a bit more professional.
I may have overlooked something, but I believe this is a fair start-over. Please apply these styles as indicated then let us see the site again to see if I’ve missed anything. DO NOT make additional changes on your own without documenting/mentioning them. Moving goalposts suck. I added a 100% width to the table as a “test feature” to show its potential width. I expect it to be limited to some max-width value after we iron out anything that has been missed.
Add somewhere:
table {
width:100%; /* ADD Me while coding to see the table's potential max size */
margin:0 auto;
}
Search1.css (line 202)
table td {
/* padding: 0 25px; /* DELETE Me. DO NOT Use padding unnecessarily */
text-align: center; /* ADD Me. */
}
Search1.css (line 211)
table th {
font-size: 20px;
padding-bottom: 30px;
padding-left: 0; /* CHANGED from 25px. DO NOT Use padding unnecessarily */
/* text-align: left; /* DEELETE Me */
}
Search1.css (line 229)
table th:nth-child(7) {
padding-left: 0; /* CHANGED from 15px. DO NOT Use padding unnecessarily */
}
Search1.css (line 233)
table th:nth-child(8) {
padding-left: 0; /* CHANGED from 15px. DO NOT Use padding unnecessarily */
}
Search1.css (line 570)
table th img {
/* margin-left: -25px; /* DELETE Me. DO NOT Use negative margins unnecessarily */
/* padding: 0 10px; /* DELETE Me. DO NOT Use padding unnecessarily */
}
At one point around 575px the logos get blown out. Why is that?
This? I took it out. I hope you don’t mind.
td:first-child img {
height: auto;
width: 100%;
}
Enter “Oxford” to make sure you get logos on all
I’ve put the smaller stars in the php file just to show you what I wanted to do. They look much better at smaller widths. And I really should mantain the state codes or it will be impossible to know which Oxford it refers to (UK, Mississipi, Alabama). Could you try and squeeze it in for it to look ok down to 300px?