HTML <ul> 元素 ( 或 HTML 无序列表元素) 代表多项的无序列表,即无数值排序项的集合,且它们在列表中的顺序是没有意义的。通常情况下,无序列表项的头部可以是几种形式,如一个点,一个圆形或方形。头部的风格并不是在页面的 HTML 描述定义, 但在其相关的 CSS 可以用 list-style-type 属性。 ul 标签需要和 li 标签结合使用。
属性说明:
HTML <ol> 元素 表示多个有序列表项,通常渲染为有带编号的列表。
属性说明:
HTML 元素 (或 HTML 描述列表元素)是一个包含术语定义以及描述的列表,通常用于展示词汇表或者元数据 ( 键-值对列表 )。
HTML 的 table 元素表示表格数据 — 即通过二维数据表表示的信息。
?>属性:(写在开头标签的里面的单词就叫做该元素的属性)
浏览器运行效果如下:
把上面表格中数字为 1 和 2 的单元格进行合并,数字为 3 和 6 的单元格进行合并。
数字为 1 和 2 的单元格分别在不同的列中所以是进行了列合并,因为只需要合并两个单元格所以 colspan 的值为 2, 列合并只需要在数字为 1 的单元格中添加属性 colspan,然后把数字为 2 的单元格删除,列合并就完成了。
数字为 1 和 2 的单元格分别在不同的行中所以是进行了行合并,因为只需要合并两个单元格所以 rowspan 的值为 2, 行合并只需要在数字为 3 的单元格中添加属性 rowspan,然后把数字为 6 的单元格删除,行合并就完成了。
浏览器运行效果如下:
举个实现HTML5响应式表格的实例,仅供参考:HTML结构如下:
<table id="miyazaki">
<caption>The Films of Miyazaki</caption>
<thead>
<tr><th>Film<th>Year<th>Honor
<tbody>
<tr>
<td data-th="Film">My Neighbor Totoro
<td data-th="Year">1988
<td data-th="Honor">Blue Ribbon Award (Special)
<tr>
<td data-th="Film">Princess Mononoke
<td data-th="Year">1997
<td data-th="Honor">Nebula Award (Best Script)
<tr>
<td data-th="Film">Spirited Away
<td data-th="Year">2001
<td data-th="Honor">Academy Award (Best Animated Feature)
<tr>
<td data-th="Film">Howl’s Moving Castle
<td data-th="Year">2004
<td data-th="Honor">Hollywood Film Festival (Animation OTY)
</table>
注意代码中的data属性,每一个单元格的data属性都与表格的header相对应。
CSS样式
表格基本的CSS样式如下:
table#miyazaki caption {
font-size: 2remcolor: #444
margin: 1rem
background-image: url(miyazaki.png), url(miyazaki2.png)
background-size: contain
background-repeat: no-repeat
background-position: center left, center right
}
table#miyazaki {
border-collapse: collapse
font-family: Agenda-Lightfont-weight: 100
background: #333color: #fff
text-rendering: optimizeLegibility
border-radius: 5px
}
table#miyazaki thead th { font-weight: 600}
table#miyazaki thead th, table#miyazaki tbody td {
padding: .8remfont-size: 1.4rem
}
table#miyazaki tbody td {
padding: .8remfont-size: 1.4rem
color: #444background: #eee
}
table#miyazaki tbody tr:not(:last-child) {
border-top: 1px solid #ddd
border-bottom: 1px solid #ddd
}
下面是响应式表格的CSS代码:
@media screen and (max-width: 600px) {
table#miyazaki caption { background-image: none}
table#miyazaki thead { display: none}
table#miyazaki tbody td { display: blockpadding: .6rem}
table#miyazaki tbody tr td:first-child { background: #333color: #fff}
table#miyazaki tbody td:before {
content: attr(data-th)font-weight: bold
display: inline-blockwidth: 6rem
}
}
media query代码中隐藏表格的头部单元,并且将每一个单元格的data-th作为标签显示在单元格内容的前面。每一行的第一个单元格都设置了特别的背景色和前景色,使之更为清晰。
扩展
你现在可以缩放浏览器来看看效果,非常不错。但是上面的代码是不可扩展的:要添加一个新行必须手动为每个单元格添加一个data-th属性。要想做到自动化,可以在服务器端实现,如PHP。也可以通过javascript来实现它。
首先,将整个表格都进行简化:
<table id="miyazaki">
<caption>The Films of Hayao Miyazaki</caption>
<thead>
<tr><th>Film<th>Year<th>Honor
<tbody>
<tr>
<td>My Neighbor Totoro
<td>1988
<td>Blue Ribbon Award (Special)
<tr>
<td>Princess Mononoke
<td>1997
<td>Nebula Award (Best Script)
<tr>
<td>Spirited Away
<td>2001
<td>Academy Award (Best Animated Feature)
<tr>
<td>Howl’s Moving Castle
<td>2004
<td>Hollywood Film Festival (Animation OTY)
</table>
然后在文档的底部添加下面的javascript代码:
<script>
var headertext = []
var headers = document.querySelectorAll("#miyazaki th"),
tablerows = document.querySelectorAll("#miyazaki th"),
tablebody = document.querySelector("#miyazaki tbody")
for(var i = 0i <headers.lengthi++) {
var current = headers[i]
headertext.push( current.textContent.replace( /\r?\n|\r/,"") )
}
for (var i = 0, rowrow = tablebody.rows[i]i++) {
for (var j = 0, colcol = row.cells[j]j++) {
col.setAttribute("data-th", headertext[j])
} }
</script>
上面的代码的意思是:获取每一个<th>中的文本内容,然后分别剔除它们的回车和换行符。然后将这些文本分别添加到适当的单元格的data属性上,添加的规则与CSS样式的规则相一致。(使用setAttribute要比dataset要好,后者只有在IE 11中得到支持。)
你好!
<style>table {
font-family: arial, 宋体, sans-serif
border-spacing: 0
border-collapse: collapse
}
tbody {
display: table-row-group
vertical-align: middle
border-color: inherit
}
td,
th {
display: table-cell
vertical-align: inherit
}
table th,
table td {
padding: 2px 10px
font-size: 12px
line-height: 22px
height: 22px
border: 1px solid #e6e6e6
}
table th {
border-bottom: 1px solid #e6e6e6
text-align: left
font-weight: 700
height: 23px
background-color: #f8f8f8
}
table.table-view {
margin: 5px 0
border-collapse: collapse
word-wrap: break-word
word-break: break-all
font-size: 12px
line-height: 22px
color: #000
}
caption {
display: table-caption
text-align: -webkit-center
}
table caption {
font-weight: 700
padding: 10px 0
padding: 8px 0 9px
font-size: 14px
}
table a {
color: #136ec2
text-decoration: none
}
</style> <table log-set-param="table_view" class="table-view log-set-param">
<caption>金满贯</caption>
<tbody>
<tr>
<th height="0" align="left">
<div class="para" label-module="para">网球奖项</div>
<div class="para" label-module="para">(英文)</div>
</th>
<th height="0" align="left">
<div class="para" label-module="para">网球奖项</div>
<div class="para" label-module="para">(中文)</div>
</th>
<th>分类</th>
<th height="0" align="left">信息</th>
</tr>
<tr>
<td width="100" height="0" align="left" valign="center" rowspan="2"><b>Golden Slam</b></td>
<td width="87" height="0" align="left" valign="center" rowspan="2">
<div class="para" label-module="para"><a target="_blank" href="/item/%E9%87%91%E6%BB%A1%E8%B4%AF"><b>金满贯</b></a></div>
<div class="para" label-module="para"><b>★★★★</b></div>
</td>
<td width="91" align="left" valign="center">年度金满贯</td>
<td valign="top" align="left" width="354">
<div class="para" label-module="para">(年度金满贯:是指一位选手在一个赛季里(一年)同时获得所有四大满贯赛事的冠军和<a target="_blank" href="/item/%E5%A4%8F%E5%AD%A3%E5%A5%A5%E6%9E%97%E5%8C%B9%E5%85%8B%E8%BF%90%E5%8A%A8%E4%BC%9A">夏季奥林匹克运动会</a>网球项目金牌。)</div>
</td>
</tr>
<tr>
<td width="91" align="left" valign="center">职业金满贯</td>
<td width="354" align="left" valign="center">(职业金满贯:是指一位选手在职业生涯中非连续夺得所有四大满贯赛事的冠军和<a target="_blank" href="/item/%E5%A4%8F%E5%AD%A3%E5%A5%A5%E6%9E%97%E5%8C%B9%E5%85%8B%E8%BF%90%E5%8A%A8%E4%BC%9A">夏季奥林匹克运动会</a>网球项目金牌。)</td>
</tr>
</tbody>
</table>
希望对你有帮助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)