Reputation: 551
I am working on a mobile app. So I need to be responsive and fit the device on width and height. I dont know how work with images and tables to get my target
This is my target
But this is what i get with CSS code
#tablebot{
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: auto;
}
And my HTML is this
<table id="tablebot">
<tr><td>..img..</td><td>..img</td></tr>
<tr><td>..img..</td><td>..img</td></tr>
<tr><td>..img..</td><td>..img</td></tr>
<tr><td>..img..</td><td>..img</td></tr>
</table>
Where img is a src with width=100% and height=auto
I need the img on each cell responsive to device screen and the table centered
I tried with vertical aling
Thanks!!
Upvotes: 0
Views: 384
Reputation: 312
You just need to insert the table inside a container div, and then give it a margin: 0 auto
. In the code snipped I readjusted the table width to 90% instead of 100% just to check that it's working:
#tablebot{
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 90%;
height: auto;
}
img {
width:100%;
height: auto;
}
.container {
margin: 0 auto;
}
<div class="container">
<table id="tablebot">
<tr><td><img src="https://unsplash.it/200" alt=""> </td><td><img src="https://unsplash.it/200" alt=""></td></tr>
<tr><td><img src="https://unsplash.it/200" alt=""></td><td><img src="https://unsplash.it/200" alt=""></td></tr>
<tr><td><img src="https://unsplash.it/200" alt=""></td><td><img src="https://unsplash.it/200" alt=""></td></tr>
<tr><td><img src="https://unsplash.it/200" alt=""></td><td><img src="https://unsplash.it/200" alt=""></td></tr>
</table>
</div>
Upvotes: 1