平时写表格都直接table然后tr td就完事了,其中还是有很多不完善的,今天按照标准写了个日历,带样式。供日后写表格提供一个参考,搞前端规范还是挺重要的
效果地址:http://codepen.io/tianzi77/pen/JdGpwj
css部分:
body {
font-family: "myriad pro", arial, helvetica, sans-serif;
font-size:16px;
line-height:1.125em; /* Baseline grid of 18px */
}
/* tables may still need 'cellspacing="0"' in the markup */
table.cal {
border-collapse: seperate;
border-spacing: 0;
text-align: center;
color: #333;
}
.cal th, .cal td {
margin: 0;
padding: 0;
}
.cal caption {
font-size:1.25em;
padding-top: 0.692em;
padding-bottom: 0.692em;
background-color: #d4dde6;
}
.cal caption [rel="prev"] {
float: left;
margin-left: 0.2em;
}
.cal caption [rel="next"] {
float: right;
margin-right: 0.2em;
}
.cal thead th {
background-color: #d4dde6;
border-bottom: 1px solid #a9bacb;
font-size:0.875em;
}
.cal caption a:link,
.cal caption a:visited {
text-decoration: none;
color: #333;
padding: 0 0.2em;
}
.cal caption a:hover,
.cal caption a:active,
.cal caption a:focus {
background-color: #6d8ab7;
}
.cal tbody {
color: #a4a4a4;
text-shadow: 1px 1px 1px white;
background-color: #d0d9e2;
}
.cal tbody td,
.cal tbody td.null:hover {
border-top: 1px solid #e0e0e1;
border-right: 1px solid #9f9fa1;
border-bottom: 1px solid #acacad;
border-left: 1px solid #dfdfe0;
}
.cal tbody tr td:first-child {
border-left: 1px solid #a9bacb;
}
.cal tbody a {
display: block;
text-decoration: none;
color: #333;
background-color: #c0c8d2;
font-weight: bold;
padding: 0.385em 0.692em 0.308em 0.692em;
}
.cal tbody a:hover,
.cal tbody a:focus,
.cal tbody a:active,
.cal tbody .selected a:link,
.cal tbody .selected a:visited,
.cal tbody .selected a:hover,
.cal tbody .selected a:focus,
.cal tbody .selected a:active {
background-color: #6d8ab7;
color: white;
text-shadow: 1px 1px 2px #22456b;
-webkit-box-shadow: inset 2px 2px 3px #22456b;
-moz-box-shadow: inset 2px 2px 3px #22456b;
}
.cal tbody td:hover,
.cal tbody td.selected {
border-top: 1px solid #2a3647;
border-right: 1px solid #465977;
border-bottom: 1px solid #576e92;
border-left: 1px solid #466080;
}
demo结构:
<table class="cal" summary="A calandar style date picker" cellspacing="0">
<caption>
<a href="#" rel="prev"><a> January 2008 <a href="#" rel="next">>a>
caption>
<colgroup>
<col id="sun" />
<col id="mon" />
<col id="tue" />
<col id="wed" />
<col id="thur" />
<col id="fri" />
<col id="sat" />
colgroup>
<thead>
<tr>
<th scope="col">Sunth>
<th scope="col">Month>
<th scope="col">Tueth>
<th scope="col">Wedth>
<th scope="col">Thuth>
<th scope="col">Frith>
<th scope="col">Satth>
tr>
thead>
<tbody>
<tr>
<td class="null">30td>
<td class="null">31td>
<td><a href="#">1a>td>
<td><a href="#">2a>td>
<td><a href="#">3a>td>
<td><a href="#">4a>td>
<td><a href="#">5a>td>
tr>
<tr>
<td><a href="#">6a>td>
<td><a href="#">7a>td>
<td class="selected"><a href="#">8a>td>
<td><a href="#">9a>td>
<td><a href="#">10a>td>
<td><a href="#">11a>td>
<td><a href="#">12a>td>
tr>
<tr>
<td><a href="#">13a>td>
<td><a href="#">14a>td>
<td><a href="#">15a>td>
<td><a href="#">16a>td>
<td><a href="#">17a>td>
<td><a href="#">18a>td>
<td><a href="#">19a>td>
tr>
<tr>
<td><a href="#">20a>td>
<td><a href="#">21a>td>
<td><a href="#">22a>td>
<td><a href="#">23a>td>
<td><a href="#">24a>td>
<td><a href="#">25a>td>
<td><a href="#">26a>td>
tr>
<tr>
<td><a href="#">27a>td>
<td><a href="#">28a>td>
<td><a href="#">29a>td>
<td><a href="#">30a>td>
<td><a href="#">31a>td>
<td class="null">1td>
<td class="null">2td>
tr>
tbody>
写在最后:这就是精通css里面的一个列子,觉得很好,敲出来留恋一下。
常规表格玩了一下,那这个怎么玩?
table-layout:fixed;
automatic 默认。列宽度由单元格内容设定。
fixed 列宽由表格宽度和列宽度设定。
看了概念晕头转向,不知道有什么用。
还是来玩个列子吧。
html
<table class="users">
<thead>
<tr>
<th class="row-1 row-ID">IDth>
<th class="row-2 row-name">Nameth>
<th class="row-3 row-job">Jobth>
<th class="row-4 row-email">Email<th>
tr>
thead>
<tbody>
<tr>
<td>0001td>
<td>Johnny Fivetd>
<td>Robotin'td>
<td>[email protected]td>
tr>
<tr>
<td>0002td>
<td>Super Superlonglastnamesmithtd>
<td>Doin' stufftd>
<td>[email protected]td>
tr>
tbody>
table>
css
.users {
table-layout: fixed;
width: 100%;
white-space: nowrap;
}
.users td {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Column widths are based on these cells */
.row-ID {
width: 10%;
}
.row-name {
width: 40%;
}
.row-job {
width: 30%;
}
.row-email {
width: 20%;
}
效果就像这样:http://codepen.io/chriscoyier/full/xFcrp
这时候再回来看看概念。很明了。
fixed的时候 不管你对td设置什么样式padding什么的。他不会超过设置的20%;
而默认的情况下就会随之内容的增加而扩充的。that’s 以上。