但是這里發現了一個問題,請仔細看最后一張圖。是不是發現圓角的邊框的菱角處裂開了!我換成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>新聞熱點
疑難解答