First DECLARE :
This is just a discussion of the use of a diagonal form of CSS simulation tables, which may actually be a bit of a fuss at work, which is not the focus of the discussion in this topic. If you think of this friend, please smile ...
Sometimes when inserting a document, use the diagonal of the table, common practice is to use the way of the picture to handle, there is to use VML to draw diagonal line, can use html+css way to realize? The answer is yes, let's touch the diagonal of a table below.
principle :
Using a border line to touch a slash, we know that if you set a div's border line wide enough to define a different color, its adjacent two border lines are diagonal. Knowing this principle, we can use Border-left and border-top to simulate the effect of a slash.
We first create a structure:
<div class= "Out" >
<b> category </b>
<em> name </em>
</div>
We use the <div class= "out" > as a diagonal container, we set the slash style, the key code is as follows:
. out{
border-top:40px #D6D3D6 solid;/* top border width equals table first row Height * *
width:0px;/* make the container width 0*/
height:0px;/* make the container height 0*/
border-left:80px #BDBABD solid;/* The width of the left border is equal to the first width of the first row of the table * *
position:relative;/* let the inside of the two sub containers absolutely positioning * *
}
<b> and <em> two labels to set up two categories, set them to block structure Display:block, clear their default font style Font-style:normal, and set them as absolute positioning because their parent container has relative positioning set. This will offset it to the location you want to specify.
b{font-style:normal;display:block;position:absolute;top:-40px;left:-40px;width:35px;}
em{font-style:normal;display:block;position:absolute;top:-25px;left:-70px;width:55x;}
Such a diagonal line is modeled. Know the principle, you can become a lot of interesting things out, wish you good luck!
This diagonal simulation also has drawbacks:
- The width height must be known
- The width of the length can not be too large, you can try to pull the width than the height of several times longer, see the effect. (For you to save some homework practice exercises)
- There is also a slash bar can not set the color.
Another: The above code only tested IE6 and FF3, other browsers did not test, please friends to test.
Here's the complete code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "/>
<title> div+css Simulation Table Diagonal </title>
<style type= "Text/css" >
*{padding:0;margin:0;}
Caption{font-size:14px;font-weight:bold;}
table{border-collapse:collapse;border:1px #525152 solid;width:50%;margin:0 auto;margin-top:100px;
th,td{border:1px #525152 solid;text-align:center;font-size:12px;line-height:30px;background: #C6C7C6;}
th{background: #D6D3D6;}
/* Analog diagonal */
. out{
border-top:40px #D6D3D6 solid;/* upper border width equals table first row high * *
width:0px;/* make the container width 0*/
height:0px;/* Let the container height be 0*/
border-left:80px #BDBABD solid;/* The left border width is equal to the first width of the first row of the table * * *
position:relative;/* Let the inside of the two sub containers absolutely positioning * *
}
b{font-style:normal;display:block;position:absolute;top:-40px;left:-40px;width:35px;}
em{font-style:normal;display:block;position:absolute;top:-25px;left:-70px;width:55x;}
. T1{background: #BDBABD;}
</style>
</head>
<body>
<table>
<caption> div+css Simulation Table Diagonal </caption>
<tr>
<th style= "width:80px;" >
<div class= "Out" >
<b> Categories </b>
<em> name </em>
</div>
</th>
<th> Grade </th>
<th> class </th>
<th> Achievements </th>
<th> class sharing </th>
</tr>
<tr>
<td class= "T1" > John </td>
<td> three </td>
<td>2</td>
<td>62</td>
<td>61</td>
</tr>
<tr>
<td class= "T1" > Dick </td>
<td> three </td>
<td>1</td>
<td>48</td>
<td>67</td>
</tr>
<tr>
<td class= "T1" > Harry </td>
<td> three </td>
<td>5</td>
<td>79</td>
<td>63</td>
</tr>
<tr>
<td class= "T1" > Zhao Liu </td>
<td> three </td>
<td>4</td>
<td>89</td>
<td>66</td>
</tr>
</table>
</body>
</html>
From: Blue Ideal