自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

學(xué)習(xí)筆記 如何使用CSS實(shí)現(xiàn)表格斜線效果

開(kāi)發(fā) 前端
本文介紹如何運(yùn)用CSS實(shí)現(xiàn)表格斜線效果用,我們知道當(dāng)網(wǎng)頁(yè)中DIV的邊框線設(shè)置得足夠?qū)?,并定義了不同的顏色時(shí),其相鄰的兩條邊框線交界處就是斜線。

你對(duì)使用CSS實(shí)現(xiàn)表格斜線效果的方法是否了解,這里和大家分享一下,當(dāng)網(wǎng)頁(yè)中DIV的邊框線設(shè)置得足夠?qū)?,并定義了不同的顏色時(shí),其相鄰的兩條邊框線交界處就是斜線,所以我們就可以利用border-left和border-top來(lái)模擬出斜線的效果。

用CSS實(shí)現(xiàn)表格斜線效果

本文是介紹如何運(yùn)用CSS實(shí)現(xiàn)表格斜線效果用,我們知道當(dāng)網(wǎng)頁(yè)中DIV的邊框線設(shè)置得足夠?qū)挘⒍x了不同的顏色時(shí),其相鄰的兩條邊框線交界處就是斜線,所以我們就可以利用border-left和border-top來(lái)模擬出斜線的效果。

首先創(chuàng)建一個(gè)結(jié)構(gòu):

示例代碼

  1. <divclassdivclass="out"> 
  2. <b>類別</b> 
  3. <em>姓名</em> 
  4. </div> 
  5.  

我們用<divclass="out">作為對(duì)角線的容器,我們來(lái)設(shè)置斜線樣式,關(guān)鍵代碼如下:

示例代碼

  1. .out  
  2. {  
  3. border-top:40px#D6D3D6solid;/*上邊框?qū)挾鹊扔诒砀?**行行高*/  
  4. width:0px;/*讓容器寬度為0*/  
  5. height:0px;/*讓容器高度為0*/  
  6. border-left:80px#BDBABDsolid;/*左邊框?qū)挾鹊扔诒砀?**行***格寬度*/  
  7. position:relative;/*讓里面的兩個(gè)子容器絕對(duì)定位*/  
  8. }  
  9.  

<b>和<em>兩個(gè)標(biāo)簽來(lái)設(shè)置兩個(gè)分類,分別將它們?cè)O(shè)置為塊狀結(jié)構(gòu)display:block;清除其默認(rèn)的字體樣式font-style:normal;因其父容器設(shè)置了相對(duì)定位,所以設(shè)置其為絕對(duì)定位,這樣可以將它偏移到你想指定的位置了。

示例代碼

  1. b{font-style:normal;display:block;  
  2. position:absolute;top:-40px;  
  3. left:-40px;width:35px;}  
  4. em{font-style:normal;display:block;  
  5. position:absolute;top:-25px;left:-70px;width:55x;}  
  6.  

這樣一個(gè)斜線對(duì)角線就模擬出來(lái)了。

◆這種對(duì)角線模擬法也有缺點(diǎn):

1.寬高度必須是已知的

2.寬高的長(zhǎng)度不能差得太大,你可以試試將寬度拉得比高度長(zhǎng)好幾倍,看看效果。

3.還有就是斜線條不能設(shè)置顏色。#p#

完整的代碼如下:

示例代碼

  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"  
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <htmlxmlnshtmlxmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5. <metahttp-equivmetahttp-equiv="Content-Type"
  6. content="text/html;charset=utf-8"/> 
  7. <title>用CSS實(shí)現(xiàn)網(wǎng)頁(yè)表格斜線-CSS在線</title> 
  8. <styletypestyletype="text/css"> 
  9. *{padding:0;margin:0;}  
  10. caption{font-size:14px;font-weight:bold;}  
  11. table{border-collapse:collapse;border:1px#525152solid;  
  12. width:50%;margin:0auto;margin-top:100px;}  
  13. th,td{border:1px#525152solid;text-align:center;  
  14. font-size:12px;line-height:30px;background:#C6C7C6;}  
  15. th{background:#D6D3D6;}  
  16. /*表格斜線*/  
  17. .out{  
  18. border-top:40px#D6D3D6solid;/*上邊框?qū)挾鹊扔诒砀?**行行高*/  
  19. width:0px;/*讓容器寬度為0*/  
  20. height:0px;/*讓容器高度為0*/  
  21. border-left:80px#BDBABDsolid;/*左邊框?qū)挾鹊扔诒砀?**行***格寬度*/  
  22. position:relative;/*讓里面的兩個(gè)子容器絕對(duì)定位*/  
  23. }  
  24. b{font-style:normal;display:block;position:absolute;  
  25. top:-40px;left:-40px;width:35px;}  
  26. em{font-style:normal;display:block;position:absolute;  
  27. top:-25px;left:-70px;width:55x;}  
  28. .t1{background:#BDBABD;}  
  29. </style> 
  30. </head> 
  31. <body> 
  32. <table> 
  33. <caption>用CSS實(shí)現(xiàn)網(wǎng)頁(yè)表格斜線-  
  34. <AhrefAhref='http://www.csscss.org'>CSS在線</A></caption> 
  35. <tr> 
  36. <thstylethstyle="width:80px;"> 
  37. <divclassdivclass="out"> 
  38. <b>類別</b> 
  39. <em>姓名</em> 
  40. </div> 
  41. </th> 
  42. <th>年級(jí)</th> 
  43. <th>班級(jí)</th> 
  44. <th>成績(jī)</th> 
  45. <th>班級(jí)均分</th> 
  46. </tr> 
  47. <tr> 
  48. <tdclasstdclass="t1">張三</td> 
  49. <td></td> 
  50. <td>2</td> 
  51. <td>62</td> 
  52. <td>61</td> 
  53. </tr> 
  54. <tr> 
  55. <tdclasstdclass="t1">李四</td> 
  56. <td></td> 
  57. <td>1</td> 
  58. <td>48</td> 
  59. <td>67</td> 
  60. </tr> 
  61. <tr> 
  62. <tdclasstdclass="t1">王五</td> 
  63. <td></td> 
  64. <td>5</td> 
  65. <td>79</td> 
  66. <td>63</td> 
  67. </tr> 
  68. <tr> 
  69. <tdclasstdclass="t1">趙六</td> 
  70. <td></td> 
  71. <td>4</td> 
  72. <td>89</td> 
  73. <td>66</td> 
  74. </tr> 
  75. </table> 
  76. </body> 
  77. </html> 
  78.  

 本文來(lái)自CSS在線:http://www.csscss.org/cssarticle/2009614134.shtml

【編輯推薦】

  1. 實(shí)例解析CSS中display屬性使用
  2. CSS樣式實(shí)現(xiàn)快速定位bug的六大技巧
  3. CSS中l(wèi)ink和@import的區(qū)別
  4. CSS2.0中page-break-after屬性用法
  5. 技術(shù)分享 使用不同CSS樣式兼容多種瀏覽器
責(zé)任編輯:佚名 來(lái)源: csscss.org
相關(guān)推薦

2021-05-19 06:07:21

CSS 斜線效果技巧

2010-09-08 09:54:16

CSS自動(dòng)換行CSS

2022-12-12 11:11:05

2010-08-31 16:35:59

CSS

2010-08-06 13:22:48

FlexCSS

2010-09-06 10:41:22

CSS內(nèi)邊距

2010-08-16 15:32:06

DIV+CSS

2024-05-28 09:21:25

2011-08-16 18:13:42

IPhone開(kāi)發(fā)UIView動(dòng)畫

2023-07-18 15:49:22

HTMLCSS

2021-07-27 07:31:16

CSS 元素切換

2016-08-30 21:05:14

JavascriptCSSWeb

2010-09-09 11:16:06

CSS交互

2010-09-09 12:49:58

鼠標(biāo)懸停tip效果CSS

2010-08-31 11:25:15

2012-01-10 14:59:42

jQuery

2010-09-14 09:18:28

DIVCSS

2010-09-14 12:58:41

DIV+CSS圓角

2010-09-07 14:53:45

Chroma屬性CSS

2021-12-27 07:45:30

CSS 技巧煙霧效果
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)