"簡單改寫Table達到RWD"
Bootstrap 4.1.1 Snippet by john8895

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <table> <caption>簡單改寫Table達到RWD</caption> <thead> <tr> <th scope="col">帳號</th> <th scope="col">日期</th> <th scope="col">金額</th> <th scope="col">期間</th> </tr> </thead> <tbody> <tr> <td data-label="帳號">Visa - 3412</td> <td data-label="日期">04/01/2016</td> <td data-label="金額">$1,190</td> <td data-label="期間">03/01/2016 - 03/31/2016</td> </tr> <tr> <td scope="row" data-label="帳號">Visa - 6076</td> <td data-label="日期">03/01/2016</td> <td data-label="金額">$2,443</td> <td data-label="期間">02/01/2016 - 02/29/2016</td> </tr> <tr> <td scope="row" data-label="帳號">Corporate AMEX</td> <td data-label="日期">03/01/2016</td> <td data-label="金額">$1,181</td> <td data-label="期間">02/01/2016 - 02/29/2016</td> </tr> <tr> <td scope="row" data-label="Acount">Visa - 3412</td> <td data-label="日期">02/01/2016</td> <td data-label="金額">$842</td> <td data-label="期間">01/01/2016 - 01/31/2016</td> </tr> </tbody> </table>
body { font-family: "Open Sans", sans-serif; line-height: 1.25; } table { border: 1px solid #ccc; border-collapse: collapse; margin: 0; padding: 0; width: 100%; table-layout: fixed; } table caption { font-size: 1.5em; margin: .5em 0 .75em; } table tr { background-color: #f8f8f8; border: 1px solid #ddd; padding: .35em; } table th, table td { padding: .625em; text-align: center; } table th { font-size: .85em; letter-spacing: .1em; text-transform: uppercase; } @media screen and (max-width: 600px) { table { border: 0; } table caption { font-size: 1.3em; } table thead { border: none; clip: rect(0 0 0 0); /*剪裁使其在畫面消失*/ height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } table tr { border-bottom: 3px solid #ddd; display: block; margin-bottom: .625em; } table td { border-bottom: 1px solid #ddd; display: block; font-size: .8em; text-align: right; } table td::before { /* * aria-label has no advantage, it won't be read inside a table content: attr(aria-label); */ content: attr(data-label); float: left; font-weight: bold; text-transform: uppercase; } table td:last-child { border-bottom: 0; } }

Related: See More


Questions / Comments: