解决table标签下的和属性宽和高设置无效
在写table表格框的时候,会遇到自己的属性设置了width: :属性和height:;属性,可预览的时候不会有任何的变化,你的表格还是一团没有任何的可看性。废话不多说,我们一起来看看吧
table{
table-layout: fixed;
}
只要在table标签里设置table-layout属性值为fixed,然后在设置width和height属性就可以改变了。
事例如下:亲测有效
table{
border: deepskyblue;
min-width: 100%;
table-layout: fixed;
}
#table-head{
overflow:auto;
display: block;
}
</style>
</head>
<div id="product_table">
<body background="sources/3.jpg">
<div id="table-head">
<table width="100px" height="60px" border="1" cellspacing="0" cellpadding="0">
<tr>
<th width="100px">商品图片</th>
<th width="100px">产品名</th>
<th width="100px">店铺价格</th>
<th width="100px">商品信息</th>
<th width="100px">热门</th>
<th width="100px">描述</th>
</tr>
<tr>
<td></td>
</tr>
</table>
下面我们来看看为什么要这样设置
通过查阅资料,知道了table-layout属性有
①automatic:(默认值)列宽度由单元格内容设定;
②fixed: 列宽由表格宽度和列宽度设定;
③inherit:规定应该从父元素继承table-layout属性的值。
这三个属性。
其中automatic为默认值,也就是说如果你不设置table-layout的属性,那么默认就是automatic值,而automatic值指定了table框内的与的width和height值为固定表格设定,所以此时你不能改变它两的值。把它设置为fixed值时为自动定表格布局,这时候就可以自由的设定width和height属性了。