1、新建一个html文件,命名为test.html。
2、在test.html文件内,使用table标签创建一个表格,并使用border属性设置表格的边框为1px。
3、在test.html文件内,使用tr、td两个标签创建表格为两行两列,代码如下。
4、在test.html文件内,编写<style type="text/css"></style>标签,页面的css样式将写在该标签内。
5、在css标签中,对table的td元素进行样式设置,使用padding属性设置单元格的间距为10px,即单元格的内边距为10px。
6、除了上面的方法外,还可以使用cellpadding属性直接在table标签内设置,实现单元格的间距定义。
内嵌标签: thead (可选)、 tbody (可选)、td、tr、colgroup 、 caption (可选)
属性:align ,bgcolor ,bordercolor,border ,cellpadding ,cellspacing ,frame ,width ,summary ,rules 。
现在的table的属性基本已经过时,都使用css进行设置table样式。
1.border-collapsecollapse | separate
collapse : border线合并
separate: border线分隔,默认属性
ps: 使用collapse 此属性时, border-spacing 、empty-cells和 border-radius 失效 ,无任何效果。
2.border-spacinghorizontal <length >| vertical <length >
3.vertical-align 设置内容与图片位置
4.table-layout auto | fixed
ps: auto 表格布局自适应宽度
fixed 表格布局固定宽度,文字内容等可能会溢出
5.caption-side 针对于caption标签的css样式设置
6.empty-cells 但单元格内无内容时候,可设置隐藏
参考:
https://www.sitepoint.com/community/t/table-format-using-css-border-issue/36882/3
https://css-tricks.com/almanac/properties/b/border-collapse/
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Table