如何确保桌子的每个单元格都应该变成正方形而不使用固定尺寸?并且当他们改变宽度时要有响应。
table { width: 90%; } td { width: 30%; } tr { /** what should go here? **/ }
<table> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> <table>
解决方法
您可以使用以下技术:
Grid of responsive squares。
使用表格和方形表单元格适应您的用户名,它将如下所示:
table { width: 90%; } td { width: 33.33%; position: relative; } td:after { content: ''; display: block; margin-top: 100%; } td .content { position: absolute; top: 0; bottom: 0; left: 0; right: 0; background: gold; }
<table> <tr> <td><div class="content">1</div></td> <td><div class="content">1</div></td> <td><div class="content">1</div></td> </tr> <tr> <td><div class="content">1</div></td> <td><div class="content">1</div></td> <td><div class="content">1</div></td> </tr> <tr> <td><div class="content">1</div></td> <td><div class="content">1</div></td> <td><div class="content">1</div></td> </tr> <table>