简体   繁体   中英

CSS table display: inline-block

 .custom-table { width: 100%; border: 5px solid black; text-align: center; border-collapse: collapse; max-width: 300px; } .right-column { width: 20%; border: 3px solid lightblue; } .middle-column { width: 40%; border: 3px solid lightblue; } .left-column { width: 40%; border: 3px solid lightblue; } 
 <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> 

I want to make tables full width until the screen can contain multiple tables side-by-side then the tables will be shown side-by-side but when I write {display:inline-block} in table CSS, it becomes like this

then what is the problem

You can achieve that using div and media query like so. Check out the effect on full page.

 .custom-table{width: 100%; border: 5px solid black;text-align: center; border-collapse: collapse;max-width: 300px;} .right-column{width: 20%; border: 3px solid lightblue;} .middle-column{width: 40%; border: 3px solid lightblue;} .left-column{width: 40%; border: 3px solid lightblue;} .table1-box, .table2-box{ width: 50%; float: left; } @media (max-width:800px){ .table1-box, .table2-box{ width: 100%; margin-bottom:30px; } } 
 <div class="table1-box"> <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> </div> <div class="table2-box"> <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> </div> 

You need to use the "float:left" or "float:right" property to allow the table or any other container (a div in my case) to float to the side of the other container. That combined with a "display:inline" or "display:inline-block" is going to give you the results you expect.

You can see it here: https://jsfiddle.net/7vxeakdw/3/

 .custom-table{width: 100%; border: 5px solid black;text-align: center; border-collapse: collapse;max-width: 400px;display:inline;} .right-column{width: 20%; border: 3px solid lightblue;} .middle-column{width: 40%; border: 3px solid lightblue;} .left-column{width: 40%; border: 3px solid lightblue;} .container{display:inline-block;} .floatright{float:right;} 
 <div class="container"> <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> </div> <div class="container floatright"> <table class="custom-table" dir="rtl"> <tr class="custom-row"> <td class="custom-column right-column"> 777 </td> <td class="custom-column middle-column"> 888 </td> <td class="custom-column left-column"> 999 </td> </tr> </table> </div> 

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