麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網站 > WEB開發 > 正文

CSS3 自定義Table

2024-04-27 15:17:49
字體:
來源:轉載
供稿:網友
<!DOCTYPE HTML><html> <head> <meta charset="utf8"> <style> body { font-family: 'trebuchet MS', 'Lucida sans', Arial; font-size: 18px; } #styleControl { position: fixed; right: 0; margin-right: 10px; padding: 10px; border: 1px solid gray; border-radius: 5px; box-shadow: 1px 1px 5px gray; background: white; opacity: 0.9; } input[name="style"] { vertical-align: middle; } #styleControl h3 { text-align: center; margin: 5px; } h2 { text-align: center; } table { width: 60%; border-spacing: 0px; border-radius: 5px; margin: 0 auto; } th, td { padding: 10px; text-align: center; } tfoot td { text-align: left; } /*--------------------------------*/ .bordered { border: 1px solid #ccc; box-shadow: 2px 2px 1px #ccc; } .bordered thead { /* 漸變的只能賦予圖像,如果賦予background-color將無效 */ background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9); } .bordered tbody tr:hover { background: #fdf8e9; } .bordered th { border-right: 1px solid #ccc; } .bordered td { border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; } /* thead 的最后一個th; tbody,tfoot 的最后一個td */ .bordered th:last-child, .bordered td:last-child { border-right: none; } /* tbody,tfoot 的最后一個tr的所有td */ .bordered tr:last-child td { border-bottom: none; } /* tbody 的第一個tr的所有td; tfoot 的第一個tr的所有td */ .bordered tbody tr:first-child td, .bordered tfoot tr:first-child td { border-top: 1px solid #ccc; } /*--------------------------------*/ .zebra { border: 1px solid #ccc; } /* 注意: border 設置在thread,tbody,tfoot或者是tr都是不會生效的. 只有設置在table或th或td才會生效 */ .zebra thead th { background-image: -webkit-linear-gradient(top, #f5f5f5, #eee); } /* 第偶數個子元素 */ .zebra tbody tr:nth-child(even) { background-color: #f5f5f5; } .zebra tfoot td { background-color: red; border-top: 1px solid #ccc; } </style> </head> <body> <div id="styleControl"> <h3>Style</h3> <hr> <input type="radio" name="style" onChange="onStyleChange()">none <br> <input type="radio" name="style" value="bordered" onChange="onStyleChange()">bordered <br> <input type="radio" name="style" value="zebra" onChange="onStyleChange()">zebra </div> <script> var title = "TIOBE Index for January 2017"; var foot = "January Headline: Google's Go is TIOBE's PRogramming language of 2016"; var ths = ["Jan 2017", "Programming Language", "Ratings"]; var languages = ["java", "C", "C++", "C#", "Python", "Visual Basic .NET", "Javascript", "Perl", "Assembly language", "php"]; var ratings = ["17.278%", "9.349%", "6.301%", "4.039%", "3.465%", "2.960%", "2.850%", "2.750%", "2.701%", "2.564%"]; var columns = [languages, ratings]; function createNoItemTable() { var h2 = document.createElement("h2"); h2.innerHTML = title; document.body.appendChild(h2); var table = document.createElement("table"); var thead = document.createElement("thead"); var row = thead.insertRow(); for(var i=0; i<ths.length; i++) { var th = document.createElement("th"); row.appendChild(th); th.textContent = ths[i]; } table.appendChild(thead); document.body.appendChild(table); } function createOneItemTable() { var h2 = document.createElement("h2"); h2.innerHTML = title; document.body.appendChild(h2); var table = document.createElement("table"); var thead = document.createElement("thead"); var row = thead.insertRow(); for(var i=0; i<ths.length; i++) { var th = document.createElement("th"); row.appendChild(th); th.textContent = ths[i]; } row = table.insertRow(); var cell = row.insertCell(); cell.innerHTML = 1; for(var i=0; i<columns.length; i++) { cell = row.insertCell(); cell.textContent = columns[i][0]; } table.appendChild(thead); document.body.appendChild(table); } function createTable() { var h2 = document.createElement("h2"); h2.innerHTML = title; document.body.appendChild(h2); var table = document.createElement("table"); var thead = document.createElement("thead"); var tfoot = document.createElement("tfoot"); var tbody = document.createElement("tbody"); //thead var row = thead.insertRow(); //row.setAttribute("align", "center"); for(var i=0; i<ths.length; i++) { var th = document.createElement("th"); row.appendChild(th); th.textContent = ths[i]; } //tfoot row = tfoot.insertRow(); var cell = row.insertCell(); cell.innerHTML = foot; cell.setAttribute("colspan", ths.length); //tbody for(var i=0; i<languages.length; i++) { row = tbody.insertRow(); //row.setAttribute("align", "center"); cell = row.insertCell(); cell.innerHTML = i+1; for(var j=0; j<columns.length; j++) { cell = row.insertCell(); cell.textContent = columns[j][i]; } } table.appendChild(thead); table.appendChild(tfoot); table.appendChild(tbody); document.body.appendChild(table); } function onStyleChange() { var tables = document.getElementsByTagName("table"); if(!tables || tables.length === 0) { return; } var value = event.target.value; if(value) { for(var i=0; i<tables.length; i++) { tables[i].setAttribute("class", value); } } else { for(var i=0; i<tables.length; i++) { tables[i].removeAttribute("class"); } } } createNoItemTable(); createOneItemTable(); createTable(); </script> </body></html>

這里寫圖片描述

這里寫圖片描述

這里寫圖片描述

但是這里發現了一個問題,請仔細看最后一張圖。是不是發現圓角的邊框的菱角處裂開了!我換成background-color也是一樣的。另外在中間那個圖的樣式上,當鼠標hover在具有圓角的項時,也是一樣的,會發現菱角處邊框斷裂。

以上問題說明了,tr或者td的背景圖或者顏色都是矩形的,不受table的border-radius屬性的限制,因此需要自行設置tr或td的邊框。

改版后的style如下

<style> body { font-family: 'trebuchet MS', 'Lucida sans', Arial; font-size: 18px; } #styleControl { position: fixed; right: 0; margin-right: 10px; padding: 10px; border: 1px solid gray; border-radius: 5px; box-shadow: 1px 1px 5px gray; background: white; opacity: 0.9; } input[name="style"] { vertical-align: middle; } #styleControl h3 { text-align: center; margin: 5px; } h2 { text-align: center; } table { width: 60%; border-spacing: 0px; border-radius: 5px; margin: 0 auto; } th, td { padding: 10px; text-align: center; } tfoot td { text-align: left; } /*--------------------------------*/ .bordered { border: 1px solid #ccc; box-shadow: 2px 2px 1px #ccc; } /* 注意: border 設置在thread,tbody,tfoot或者是tr都是不會生效的. 只有設置在table或th或td才會生效 */ .bordered thead { /* 漸變的只能賦予圖像,如果賦予background-color將無效 */ background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9); } .bordered tbody tr:hover { background: #fdf8e9; } .bordered th { border-left: 1px solid #ccc; } .bordered th:first-child { border-radius: 5px 0 0 0; border-left: none; } .bordered th:last-child { border-radius: 0 5px 0 0; } /* 如果只有唯一的一個th */ .bordered th:only-child { border-radius: 5px 5px 0 0; } .bordered td { border-top: 1px solid #ccc; border-left: 1px solid #ccc; } /* thead 的最后一個th; tbody,tfoot 的最后一個td */ .bordered td:first-child { border-left: none; } /* tbody 的第一個tr的所有td; tfoot 的第一個tr的所有td */ .bordered tfoot td:only-child { border-top: 1px solid #ccc; border-radius: 0 0 5px 5px; } /*--------------------------------*/ .zebra { border: 1px solid #ccc; } /* 注意: border 設置在thread,tbody,tfoot或者是tr都是不會生效的. 只有設置在table或th或td才會生效 */ .zebra th { background-image: -webkit-linear-gradient(top, #f5f5f5, #eee); } .zebra th:first-child { border-radius: 5px 0 0 0; } .zebra th:last-child { border-radius: 0 5px 0 0; } /* thead 的唯一一個th */ .zebra th:only-child { border-radius: 5px 5px 0 0; } /* 第偶數個子元素 */ .zebra tbody tr:nth-child(even) { background-color: #f5f5f5; } /* tfoot 的唯一一個td */ .zebra tfoot td:only-child { background-color: -webkit-linear-gradient(bottom, #ebf3fc, #dce9f9); border-top: 1px solid #ccc; border-radius: 0 0 5px 5px; }</style>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄色片快播 | 久久综合网址 | 午夜久久久精品一区二区三区 | 日韩视频在线一区二区三区 | 91av在线免费播放 | 日韩一级电影在线观看 | 毛片视频网站 | 一区二区三区在线观看国产 | 99精品视频免费看 | 欧美乱码精品一区 | 国产品久久| 亚洲综合网站 | 91麻豆精品国产91久久久无需广告 | 在线免费亚洲 | av观看国产 | 三级国产三级在线 | 性大片免费看 | 天天看天天摸天天操 | jizzjizz中国人少妇中文 | 精品免费在线视频 | 黄色片免费看看 | 97porn| 精品国产一区二区三区久久久蜜月 | 国产毛片毛片 | 欧美3p激情一区二区三区猛视频 | 欧洲精品久久 | 日本黄色一级电影 | 中文字幕观看 | 久久福利剧场 | 日韩av在线播放一区 | 国产黄色一区二区 | 在线播放视频一区二区 | 欧美一a一片一级一片 | 成人店女老板视频在线看 | 午夜国产在线 | 欧洲精品久久久久69精品 | 久久亚洲成人 | 亚洲成在人 | 91久久夜色精品国产网站 | 噜噜社| 成人免费观看49www在线观看 |