сейчас на сайте:
Лучшие сказки мира
Детектив и фантастика
Песни прошлых лет
Для досуга
смотреть оглавлениепримерразмер кода
This first example shows a table using a standard border to set 1.
<table border="1" height="100px"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
Applying a border colour using the table attribute bordercolor gives you
<table border="1" height="100px" bordercolor="red"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
With the tables border set to zero a border is applied using css. You will notice that there are no cell borders.
<table border="0" style="height:100px;border:1px solid blue"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
If you set the tables border and also apply a border using css this is what you see. In Mozilla the tables bordercolor is not applied.
<table border="1" bordercolor="red" style="height:100px;border:1px solid blue"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
You could apply a different colour, width, or type to each of the tables sides by using the individual border attributes. border-top:2px solid green border-right:4px solid yellow border-bottom:6px solid red border-left:8px solid border
<table border="0" style="height:100px;border-top:2px solid green;border-right:4px solid yellow; border-bottom:6px solid red;border-left:8px solid blue"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
As with the table each cell can have its own border
<table border="0" style="height:100px"> <tbody> <tr> <td style="border:1px solid blue">Cell 1 content</td> <td style="border:1px solid blue">Cell 2 content</td> <td style="border:1px solid blue">Cell 3 content</td> </tr> <tr> <td style="border:1px solid blue">Cell 4 content</td> <td style="border:1px solid blue">Cell 5 content</td> <td style="border:1px solid blue">Cell 6 content</td> </tr> </tbody> </table>
So now you could have the table and its cells with individual borders
<table border="0" style="height:100px;border:2px solid white"> <tbody> <tr> <td style="border:1px solid green">Cell 1 content</td> <td style="border:1px solid black">Cell 2 content</td> <td style="border:1px solid yellow">Cell 3 content</td> </tr> <tr> <td style="border:1px solid red">Cell 4 content</td> <td style="border:1px solid black">Cell 5 content</td> <td style="border:1px solid blue">Cell 6 content</td> </tr> </tbody> </table>
As well as colouring the borders you can also add a background color and/or images
<table border="0" style="height:100px;border:2px solid white;background-color:gold"> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> <td>Cell 3 content</td> </tr> <tr> <td>Cell 4 content</td> <td>Cell 5 content</td> <td>Cell 6 content</td> </tr> </tbody> </table>
Either to the entire table or individual cells
<table border="0" style="height:100px;border:2px solid white"> <tbody> <tr> <td style="background-color: green">Cell 1 content</td> <td style="background-color: silver">Cell 2 content</td> <td style="background-color: yellow">Cell 3 content</td> </tr> <tr> <td style="background-color: red">Cell 4 content</td> <td style="background-color: white">Cell 5 content</td> <td style="background-color: blue">Cell 6 content</td> </tr> </tbody> </table>
With images
<table border="0" style="height:120px;border:4px solid white;padding:10px;background-color:#800000"> <tbody> <tr> <td style="background-image:url(../imagery/image000.jpg)">Cell 1 content</td> <td style="background-image:url(../imagery/image001.jpg)">Cell 2 content</td> <td style="background-image:url(../imagery/image003.jpg)">Cell 3 content</td> </tr> <tr > <td style="border:1px solid white;background-image:url(../imagery/image004.jpg)">Cell 4 content</td> <td style="border:1px solid white;background-image:url(../imagery/image006.jpg)">Cell 5 content</td> <td style="border:1px solid white;background-image:url(../imagery/image031.jpg)">Cell 6 content</td> </tr> </tbody> </table>
Note. While many CSS attibutes can be applied to the table and its cells the margin attribute does not work on the table cells so cellspacing still has to be used.
All the above examples use inline styles, if you only have one table in your page or you want all the tables in the page to be the same you can create style rules and embed them in the head section.
<style> table{ border:1px solid red; } td{ border:1px solid blue; } </style>
To style individual tables give them an ID and create ID selector rules to suit
<style> #table1{ border:1px solid green; } #table1 td{ border:1px solid yellow; } #table2{ border:1px solid red; } #table2 td{ border:1px solid blue; } </style> <table border="0" id="table1> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> </tr> <tr> <td>Cell 3 content</td> <td>Cell 4 content</td> </tr> </tbody> </table> <table border="0" id="table2> <tbody> <tr> <td>Cell 1 content</td> <td>Cell 2 content</td> </tr> <tr> <td>Cell 3 content</td> <td>Cell 4 content</td> </tr> </tbody> </table>