简体   繁体   中英

How to align responsive image side by side with table

I have one table on the right side and i want to have an image on the left side aligned with the table. The problem is that when resize the page, the image size dosen't follow the table.

 .div-contains{ background-image: url("http://www.castan.pt/castan/wp-content/uploads/2014/07/img-teste-02.jpg"); position: relative; background-repeat: no-repeat; background-size: 100%; }.div-forum{ overflow-x:auto; background-color:white; width:75%; } table { border-collapse: collapse; border-spacing: 0; width: 100%; } th, td { text-align: left; padding: 8px; } tr{ border-bottom: 1px solid #ddd; }
 <;DOCTYPE html> <html> <head> <style> </style> </head> <body> <div class="div-contains" > <div class="div-forum" > <table> <tbody> <tr> <td>0</td> <td>1</td> <td>2</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> </tbody> </table> </div> </div> </body> </html>

I would like to have table and image syde by side and when someone resize screen both have the same size. https://imgur.com/lMNkOdi.png

If you must set image as background and set it on the right, here you go:

In your div-contains set this property:

background-size: 25%; /* From a 100% set 25% as your table width take 75% */
background-position: right; /* set it to the right */

DEMO

 .div-contains{ background-image: url("http://www.castan.pt/castan/wp-content/uploads/2014/07/img-teste-02.jpg"); position: relative; background-repeat: no-repeat; background-size: 25%; /* From a 100% set 25% as your table width take 75% */ background-position: right; /* set it to the right */ }.div-forum{ overflow-x:auto; background-color:white; width:75%; } table { border-collapse: collapse; border-spacing: 0; width: 100%; } th, td { text-align: left; padding: 8px; } tr{ border-bottom: 1px solid #ddd; }
 <;DOCTYPE html> <html> <head></head> <body> <div class="div-contains" > <div class="div-forum" > <table> <tbody> <tr> <td>0</td> <td>1</td> <td>2</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> <tr> <td>&nbsp;</td> <td>yrdyr</td> <td>yrdyr</td> </tr> </tbody> </table> </div> </div> </body> </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM