我有代码 https://jsfiddle.net/ang3lwish/dnt4pv6m/2/
<div style="border:1px solid yellow;display:block;">
<table border=1 align="center">
<tr>
<th>No.</th>
<th>Name</th>
<th>Address</th>
<th>Gender</th>
<th>Email</th>
</tr>
<tr>
<td>
1.
</td>
<td>
Anto
</td>
<td>
Padang
</td>
<td>
Male
</td>
<td>
anto@gmail.com
</td>
</tr>
</table>
<br>
</div>
我想div宽度(行黄色)是跟随表格宽度?
但我不知道如何设置CSS?
答案 0 :(得分:1)
制作表格宽度100%
添加这是您的table
代码
<table border=1 align="center" width="100%">
答案 1 :(得分:0)
如果您希望表格适合div,则需要将100%宽度放在表格中
<table width="100%">
表根据div调整自身。干杯:)
答案 2 :(得分:0)
如果你想在没有css的情况下跟随黄线(即你的div),那么在你的表属性中使用width = 100%但是再次使用它对于正确设置div中的表没有多大帮助,所以最好使用这个: 在css:
.pad
{
padding-top: 25px;
padding-right: 50px;//set as you like them//
padding-bottom: 25px;
padding-left: 50px;
}
然后在表格中包含此类:
<table border=1 align="center" class="pad">