Create a table using CSS
Posted April 9, 2009
on:- In: CSS | HTML
- 16 Comments
Few days back my colleague was developing a website using Div’s. It was very difficult for him to create a structure of table using div’s. So he asked me for look for some way to develop such a structure like a table.
Here is how we can do it, its so simple and easy to understand. Down below are the html and css for the same
HTML code :
<html>
<head>
<title>Creating a table using CSS</title>
</head>
<body>
<h1>Test Rankings</h1>
<div class=”table”>
<ul>
<li class=”title”>Rank</li>
<li class=”even”>1</li>
<li class=”odd”>2</li>
<li class=”even”>3</li>
<li class=”odd”>4</li>
<li class=”even”>5</li>
</ul>
<ul>
<li class=”title”>Team</li>
<li class=”even”>Australia</li>
<li class=”odd”>South Africa</li>
<li class=”even”>India</li>
<li class=”odd”>Srilanka</li>
<li class=”even”>Pakistan</li>
</ul>
<ul>
<li class=”title”> Points</li>
<li class=”even”>5361</li>
<li class=”odd”>5360</li>
<li class=”even”>5498</li>
<li class=”odd”>3680</li>
<li class=”even”>2197</li>
</ul>
<ul>
<li class=”title”>Rating</li>
<li class=”even”>128</li>
<li class=”odd”>119</li>
<li class=”even”>117</li>
<li class=”odd”>108</li>
<li class=”even”>100</li>
</ul>
</div>
</body>
</html>
CSS code:
<style type=”text/css”>
.table
{
background:#333;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
.table ul
{
float:left;
margin:0;
padding:0;
border:1px solid #C9C9C9;
}
.table ul li
{
list-style:none;
padding:5px 10px;
}
.table ul li.title
{
font-weight:bold;
background:#333;
color:#fff;
}
.table ul li.even
{
background:#fff
}
.table ul li.odd
{
background:#D7EDFB
}
h1{
font-size:16px;
color:#227786;
}
</style>
16 Responses to "Create a table using CSS"
Another option is to use floating divs in the very same manner you used the UL’s, and with divs you’re open to use all sorts of extra parameters. This tutorial isn’t very useful at all, in that it’s an easier way out of the TRUE div-table css method.
Have you ever tested this code?
its doesnt work with me, am i miss something?
already put css code in too
i m not getting a table .
I have pasted the above code in notepad and saved it. When i open in IE an FF i am not getting the table
Can you please help me .
When i type some very big string in one of the column, the other columns are displaying as a new row. This scenario is not going to happen always. But still if you could give me a suggestion to wrap the text when the entire table is fulfilling the width of the screen. (Just like Table tag, if we have some bigger txt, it will wrap automatically)
Thanks
Sathish
hi!, nice tips
how to add hover effect entire row?
This works great. . just what I was looking for. . .I plan to mix in a sprinkle of jQuery and this is perfect! Thanks!
1 | Nate
April 9, 2009 at 4:16 pm
Why not just use a table tag?
Amit Nazare
April 9, 2009 at 5:50 pm
Its an another option, instead of using table tr, td’s blah blah… just use div’s or ul’s and CSS..