Building a poker template
What a structured document looks like
We have carefully constructed all the markup for the important parts of the site. Notice that we’ve said nothing about the look of it yet, we’re strictly dealing with content.
We will first add all a good doctype (strict), character encoding and the other things needed for validation. I will not go over this again, it was described a couple of weeks ago in the third page of the beginner’s guide. This is just copy and paste, so don’t skip this part.
Aside from that we also need to add some “hooks”, namely classes and ids, to make it easier to style the document (If you don’t know what those two are I recommend you read through the beginners guide before continuing). Good class and id names have something in common: they describe the content. So using “tinyredbar” is a bad name and using “latestnews” is a good one.
The basics, the bits of HTML we constructed above and the hooks, together form a good logical structure to start with. When looking at that page you will notice that it doesn’t look pretty. When you view the source of it you will see though - that’s what I want to see when I look at the source of your front page. I get all warm when thinking about it; pure, logical, and accessible content. It’s now time to position things where we want them.
Apply some fancy CSS
For me the design part always starts with an image program of some sort (Macromedia Fireworks lately for its ease of use). After a while of fiddling around with images and colors I decided to go for something like this draft (Note that I’m a programmer rather than a designer so don’t expect wonders here :).
When you site there with your image in front of you and are on your way to start with the CSS there is one thing you should remember: do the positioning before you do the decoration. The positioning is the hard part and it will get even harder if you start to mix in colors and fonts. Let’s all follow what I just said and start with the positioning.
Think of every tag you have on your page as a little box. By enabling borders on all your elements you can get a good idea of what I’m talking about. When deciding how to position these boxes it’s always wise to start to look at “the flow” of the document. The flow is what you just saw when you looked at the structure above, content is just stacked on top of each other and most tags occupy the full width. By using some clever combinations of floats, clears and widths/heights it is possible to things to line up like we want.
Positioning the header
Let’s start by looking at the top. There seems to be four boxes here: a company name, company info, statistics, and the play button. The big image to the right can be added as a background, so we’ll wait with that one. The first two boxes just need a smaller width to be where we want them (compare with how they where positioned in default flow). The last two ones need to be floated left and given a width (this will place them side by side).
#header h1 {
height: 65px;
width: 400px;
}
#header p {
width: 400px;
}
#header ul {
float: left;
width: 130px;
}
#header a {
display: block;
height: 84px;
width: 261px;
}
Positioning the navigation
Next up we will deal with the navigation and search. Start by adding clear: both to the navigation to make sure we are below any floats from earlier in the code. To make the navigation list horizontal we add display: inline; to all list items. We complete the navigation by setting a width on the list and floating it left.
The search box is a bit harder. All that info won’t fit in the tiny space we have left so my idea is that we hide the fieldset, legend and label. “Why go through the fuzz of adding them and then hiding?”, I hear you shout. Relax. They’re there because they help users that surf the site with CSS turned off, people like your rich grandmother (using Netscape 4), blind users (using screen readers) and Google. Visual users still know that the textbox is for searching because of the “Search” on the button afterwards, so we’re not hiding important information. Ohh, and the header won’t fit our design either so let’s hide that too.
#navigation {
clear: both;
height: 41px;
width: 720px;
}
#navigation ul {
float: left;
list-style: none;
width: 400px;
}
#navigation li {
display: inline;
}
#navigation form {
float: right;
width: 250px;
}
#navigation legend, #navigation label, #navigation h2 {
position: absolute;
left: -10000px;
text-indent: -10000px;
line-height: 0;
}
#navigation fieldset {
border: none;
}
Positioning the advertisements
Ahhh, ads, both hated and loved at the same time. Not to include ads on a big site like this would just look strange. Let’s position it like we want. First move it down below the navigation by clearing. Then float it right to get it out of the way from the content below.
#adverts {
clear: both;
float: right;
}
Positioning the content
This is going well; the content is next up for positioning. Note that I added a couple of divisions to this part of the HTML when merging. They will come to good use now as holders of the four sections. Each of the boxes is given a specific width and height and gets floated left.
#content div {
float: left;
height: 200px;
width: 240px;
}
Phew, this feels like a whole days work doesn’t it? On the last page of this tutorial we will put all positioning together and show an example of how everything looks when decorated. Click next below.
Velaluka ( 24 Jan 2006 )
Transitional is used more: maybe just to use depreciated HTML in strict?
These sort of sites are not made by webdesign pros that use standards but seems more developers that know some CSS and other.
Or maybe the templates are faulty?
Emil Stenström ( 25 Jan 2006 )
@Velaluka: I think you can blame templates in some cases. I know a lot of developers that I would like to give this tutorial to though.
Being valid Transitional is surely better than not being valid at all, it’s just that there’s no reason to use that doctype. As I say in my cross browser tutorial transitional can get you in troubles…
Velaluka ( 26 Jan 2006 )
“As I say in my cross browser tutorial transitional can get you in troubles…”
doctype switching?
box model IE?
Jeff Mackey ( 2 Feb 2006 )
Very cool tutorial. I look forward to additions in this series! Thank You.
Todd Currie ( 10 Feb 2006 )
Great study template, Tks.
Do you have a table detailing descriptor options and their effects? Some formats you use puzzle me
font: 80%/1.4em Arial
margin: 40px 40px 0 0;
margin: 2em auto 0;
list-style: none;
Tks again look forward to more learning.
Emil Stenström ( 10 Feb 2006 )
@Todd Currie: I skipped going over all the details in the last step. Here’s a short explaination of the four lines you pasted:
1) font Sets font-size to 80% of the users default and a line-height of 1.4em (I could have used 140% too, don’t know why I didn’t). Also sets the font-family to Arial.
2, 3) margin margin takes one, two, three or four values. I’ll write a short article about this in the future, stay tuned!
4) list-style removes the bullets on a list which makes them look better.
Jordan Stewart ( 2 Jun 2006 )
Hi. I’m a newbie to CSS and I’m just wondering what the reasoning behind using
#navigation legend, #navigation label, #navigation h2 {
position: absolute;
left: -10000px;
text-indent: -10000px;
line-height: 0;
}
is over using
#navigation legend, #navigation label, #navigation h2 {
display: none;
}
or
#navigation legend, #navigation label, #navigation h2 {
visibility: hidden;
}
Emil Stenström ( 2 Jun 2006 )
@Jordan Stewart: Good question. The reason is that screen readers are known to hide things with display: none, something that defeats the purpose of adding it in the first place. It’s a bit annoying but at least the workaround is not that hard.
Visibility: hidden; would not remove the element, it would still take up space.
Adam Zakreski ( 8 Jun 2006 )
When you chose not to display the legend and text for the search button, it appears you just used indent to push it off the left of the screen. Why did you do this instead of doing a {display:none}?
Great site it’s been really informative!
Travis ( 27 Oct 2006 )
The only problem I have with the layout is that when you drag the window size, the advertisement, nav bar, and the “4,379 people online part” move all over the place. How can one fix this?
Emil Stenström ( 28 Oct 2006 )
@Travis: Thanks for pointing that out. It has to do with the IE6 resize bug and I applied the fix to it. Does it work better for you now?
Emil Stenström ( 28 Oct 2006 )
@Adam Zakreski: I answered that in the comment above yours.
Karla ( 19 Mar 2007 )
How would you get started to build your own poker site?
Andrew ( 1 Jun 2007 )
it looks good, but if you make the text larger (eg if you have bad eyesight) it overflows its boxes. Is this is fundamental problem with the method/css?
Emil Stenström ( 2 Jun 2007 )
@Andrew: it has to do with me setting the height of the boxes to 200px. Change it to 10em instead and it should work better when zoomed. Thanks for reading!
Ronn ( 28 Nov 2007 )
Nice site, very nice tutorial. Only bug I can see in this whole thing is that it’s really unnecessary for theses sites to do almost any onsite optimization. The degree of offline optimization these guys do is remarkable. Check them out in backlinks, you will be surprised at how many people link to them.