Tekforums

Chat => Entertainment & Technology => Topic started by: shiftlocked on June 25, 2007, 11:00:05 AM

Title: Css Table Design
Post by: shiftlocked on June 25, 2007, 11:00:05 AM
Hi everyone.

Wonder if someone could help me out.  Im trying to use css styles to format a table.

In html I have a table with 2 columns, column 1 is 30% and the 2nd one is 70% and the whole table is designed to take up 95% of space.

Cell padding is 5 and Cell spacing is 3 and of course the table is centered.  Below is the html that Ive used thus far.

Quote
 
   
   
 
 
   
   
 
Nameme
addresshere


As I use this sort of table on a lot of pages Id like to chuck a hand in and use a bit of css.  So Ive done the following

Created a class called .TechTable

Quote.TechTable
{
   width: 95%;
   FONT-SIZE: smaller;
    FONT-FAMILY: Arial;
   margin-left: auto;
   margin-right: auto;
   }

and then one for the left column that has the following

Quote.TechLeftColumn
{
   FONT-FAMILY: arial;
   FONT-WEIGHT: bolder;
        FONT-VARIANT: small-caps;
   border-style: dashed, 1px;
   border-bottom-width: thin;
   padding: 5px;
   width:33%;
}

Now from what Ive worked out.....

There is no equivilant for cell spacing at the moment (been and googled that one)
I also need a definition in the CSS for the right hand column?

Can anyone help me make  the CSS do the same this as that I do with the html version of my table?  I have done a bit of googling but not really got anywhere so Id like to take some advice from the people who know :D

Thanks
Title: Re:Css Table Design
Post by: neXus on June 25, 2007, 11:23:35 AM
Hello :)
First of all tables suck :) not used one in two years :)

Another tip - do your code in lower case not upper case
Do you know your missing your class declarations in your table?



then when you create css for the table elements you can do..
tr.TechTable {
}


There is no css for cell spacing etc, you have to put that in your html table elements, the css you have is fine, cell spacing and padding is only html and why tables are being slowly removed from peoples code on the web.
You seem to know the idea that html is the layout, css is the style and format and your server side elements is your content etc.

can do everything as a table and more, its harder to know how to do everything but like clockedone will tell you who I have helped in his learning of it once you begin to follow it they are a better option.

Hope that was what you ment and after.
Title: Re:Css Table Design
Post by: shiftlocked on June 25, 2007, 11:47:39 AM
Thanks for getting back to me.  I didnt post the code for when I used the CSS stuff on my template.  Sorry about that.

I think I looked at divs but no matter what I did I couldnt get them to look like a table if that makes sense.  Will have a lookie now and see what I can come up with.

If you have any links to DIV tutorials that you recommend that would be great.
Title: Re:Css Table Design
Post by: neXus on June 25, 2007, 12:26:04 PM








one cell of content in a table

one cell of content in a  table



one cell of content in a table

one cell of content in a  table






http://alistapart.com/articles/practicalcss/
http://www.dev-archive.net/articles/table-in-css.html
Title: Re:Css Table Design
Post by: shiftlocked on June 25, 2007, 14:24:40 PM
Thanks for the help. Looking into this already.

The problem that I have is that Im trying to modify the CSS so that when I get my information from the source I can display with the same tags just using CSS to manipulate the style if that makes sense?  Thats why I was wondering what formatting I could do with those tags



Title: Re:Css Table Design
Post by: neXus on June 25, 2007, 14:31:27 PM
Then just create another set of code to represent the table layout which is exactly the same as the above but with different content.
Title: Re:Css Table Design
Post by: shiftlocked on June 25, 2007, 15:00:54 PM
Am I being very dense or does this code just show 4 rows saying "one cell of content in a table?"
Title: Css Table Design
Post by: Mardoni on June 25, 2007, 15:09:11 PM
Looking at the code, Id have said 2 rows of 2 columns; 4 cells total.
Title: Re:Css Table Design
Post by: shiftlocked on June 25, 2007, 15:27:49 PM
just 4 rows here  :(
Title: Css Table Design
Post by: Sweenster on June 25, 2007, 16:26:07 PM
probably due to float, as some browsers insist on putting a new div on a new line, only way to get around that is float... which is a little buggy
Title: Css Table Design
Post by: Sam on June 25, 2007, 16:28:41 PM
nige is your man, hes css god
Title: Re:Css Table Design
Post by: Clock'd 0Ne on June 25, 2007, 17:11:10 PM
What you had in the first post was fine, although you dont need to explicitly set width for the second table cell as you have already defined your table width (95%) as well as the first table cell width (30%), then second cell will take up the remaining available slack space.

Dont feel pressured to start replacing all your tables with divs, tables are still useful and are perfectly valid, the argument gets banded backward and forwards about using them, but if big sites like Google, etc are happy using them so am I and thats at a professional level. Using divs often requires a lot of floating and hacks to work on all browsers for things like page footers that sit at the bottom of the screen that are done easily with tables.

You can reduce your CSS down as well, you have a lot of unnecessary markup going on and dont get too reliant on CSS2 tags, keep things simple. font-weight: bold; is fine, you dont need font-weight: bolder; as it does nothing different at the moment.

for instance:
border-style: dashed, 1px;
border-bottom-width: thin;

can become:
 border: 1px dashed thin;

This is an excellent resource for reference to CSS properties and browser compliancy:
http://www.blooberry.com/indexdot/css/propindex/all.htm#
Title: Re:Css Table Design
Post by: neXus on June 25, 2007, 17:22:56 PM
shiftlocked, you can always add more, I only typed it up fast as an example.

Just to add to clockeds post

For mutliple border types of different types or an object with different widths on the top, bottom etc..

--> border: 1px 3px 4px 5px;
In the order of - top right bottom left
same with padding and margins


 margin-left: auto;
margin-right: auto;


can be

margin-right, margin-left: auto;
Title: Re:Css Table Design
Post by: neXus on June 26, 2007, 16:26:41 PM
How you getting on with it shiftlocked ?
Title: Re:Css Table Design
Post by: shiftlocked on June 27, 2007, 11:30:12 AM
Hi Guys,
Thanks for all the help, had forgotten about these forums till a short while ago.

With regards to the divs and floats and stuff, im not too proud to admit that its a bit complex for me at the moment, I understand it but its a question of time to learn it.

Thanks for the help in reducing the css code.  Could anyone help me with the CSS side to make the table look half decent so that it would look good displaying the details like the example I gave.  Just want it to look a bit more... ermm ... nicer lol

I had an idea of alternating row colours but dont think that can be done with CSS??
Title: Re:Css Table Design
Post by: Clock'd 0Ne on June 27, 2007, 14:35:16 PM
Alternating table row colours can be done easily with CSS.
give the alternating
s classnames of "rowA", "rowB", etc.

then just refer to
tr.rowA td { background: #333; }
tr.rowB td { background: #555; }

Piece of cake.

Ill give you a very nice layout later tonight when i have time.
Title: Re:Css Table Design
Post by: shiftlocked on June 29, 2007, 10:41:26 AM
interesting.  In FireFox, the dashed border doesnt appear but in IE it does.   God.. cross browser compatibility issues here I come
Title: Re:Css Table Design
Post by: Clock'd 0Ne on June 29, 2007, 10:49:02 AM
Both browsers should render the dashed border, albeit slightly differently. Paste your CSS for me, please?

Also get into good habits, start your sites with some uniformity and overwrite default browser settings for certain elements, like body and form margins, setting a default font for the site to use:


body, form { padding: 0; margin: 0; }
body { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-size: 12px; color: #656565; }

a img { border: 0; }

a { color: #333333; text-decoration: none; }
a:hover { color: #000000; text-decoration: none; }


I would also recommend you stop using imprecise measures like thin thick and use precise measures like pixels instead, you can guarantee how your sites will be rendered then.

Title: Re:Css Table Design
Post by: shiftlocked on June 29, 2007, 11:02:44 AM
Thanks for getting back to me Clockd help is muchos appreciated :D



.TechTable
{
width: 95%;
margin: auto;
padding: 15px;
border-collapse: collapse;
FONT-SIZE: smaller;
FONT-FAMILY: Arial;
}

.TechLeftColumn
{
width: 30%;
        text-align: left;
padding: 5px;
border-style: dashed, 1px;
}

.MainleftColumn
{
    FONT-SIZE: smaller;
    BACKGROUND-COLOR: #ffffcc
}
Title: Re:Css Table Design
Post by: neXus on June 29, 2007, 11:51:02 AM
First of all - all lower case m8, keep everything lowercase and avoid using case in css and your xhtml
I know if you program you would make a function myClass in its naming format but in xhtml and css keep it lower case and your missing   a ; on your last line of code

w3 is the place to help you out by the way: http://www.w3schools.com/css/css_border.asp

Title: Re:Css Table Design
Post by: shiftlocked on June 29, 2007, 13:17:38 PM
(edited, intelligence chip just kicked in..)

Ill be changing things to keep lower case shortly, thanks for the tip and Oooops on that last;

.TechTable
{
width: 95%;
margin: auto;
padding: 15px;
border-collapse: collapse;
font-size: smaller;
font-family: Arial;
}

.TechLeftColumn
{
width: 30%;
    text-align: left;
padding: 5px;
border-bottom: 1px dashed #00FF00;

}


Thats the updated code, so from what I gather at the moment (please bear with me)

Centered Table
95% of the broswer screen
borders treated as one
Small Fonts

Left hand column
30% width
padded
and has a 1px green dash on there.

Am I correct in assuming that to set a style for the right hand column I would have to create another CSS style?
Title: Re:Css Table Design
Post by: neXus on June 29, 2007, 13:35:56 PM
yes

If it different to the other

(small thing but still - your colour hex code - lower case :)
Title: Css Table Design
Post by: Sam on June 29, 2007, 15:12:38 PM
Dont worry about divs. Theyre a load of bollocks used by people who dont design sites for a living but design them for fun and thus can mess about for 12 hours to do what takes 10 minutes in a table.
Title: Re:Css Table Design
Post by: shiftlocked on June 29, 2007, 15:26:19 PM
Is there a way to make the background in the left column only populate say 80% of the cell?

Title: Re:Css Table Design
Post by: neXus on June 30, 2007, 01:28:36 AM
Quote from: shiftlockedIs there a way to make the background in the left column only populate say 80% of the cell?

Not with tables no
Ignore Sam, he just cant grasp divs and css at all and what he cant grasp he tends to hate out right :( Clocked on the other hand picking it all up very well
And you can make full blown sites with easse as a working profession (since the company my brother works for does and so do most decent companies now :) )
Title: Css Table Design
Post by: Sam on June 30, 2007, 01:55:09 AM
Look nige agrees with me and so do google.
QED.
Title: Re:Css Table Design
Post by: neXus on June 30, 2007, 10:19:25 AM
Funny how you like google and their opinion but not the iphone although they are putting a lot of money into and will be releasing more applications on it over time and they think it will be a big thing, but you dont  :P
Title: Re:Css Table Design
Post by: Clock'd 0Ne on July 02, 2007, 09:44:24 AM
Quote from: shiftlockedIs there a way to make the background in the left column only populate say 80% of the cell?


If you mean you want it to sit 20% inset just use background-position: 20% top;
Title: Re:Css Table Design
Post by: shiftlocked on July 02, 2007, 11:20:46 AM
I just found a really nice program for the mac CSSEdit which is making things a lot easier.

Today I r going to be with the table row and seeing how the color thing goes and then the background inset thing that was posted.  Can I just say again thanks to people for helping a noob out here :D

Divs and Floats... after I got this done thats my next thing :D
Title: Re:Css Table Design
Post by: shofty on July 02, 2007, 11:38:54 AM
Quote from: shiftlockedDivs and Floats... after I got this done thats my next thing :D

need to read this then.

http://www.brainjar.com/css/positioning/

read it a few times. it takes a while to make sense of it.

Matt
Title: Re:Css Table Design
Post by: shiftlocked on July 02, 2007, 16:44:48 PM
QuoteIf you mean you want it to sit 20% inset just use background-position: 20% top;

Isnt that jsut for background images and not for borders?
Title: Re:Css Table Design
Post by: neXus on July 02, 2007, 17:14:34 PM
Quote from: shiftlocked
QuoteIf you mean you want it to sit 20% inset just use background-position: 20% top;

Isnt that jsut for background images and not for borders?

Yes, but what do you want to do with your borders?