PDA

View Full Version : Absolute Positioning


pageoneresults
03-03-2002, 22:59/10:59PM
Good evening everyone! I was going to post this in the tips section but I thought this new forum would be more appropriate. My username is appearing too many times down there anyway! ;)

These past seven days have truly been an accelerated learning experience for me. I built my first page using pure CSS (nadda table), and also validated with the W3C for 4.01 Transitional.

CSS and Absolute Positioning (http://www.seoconsultants.com/css-test.htm)

I'm currently in the process of converting the entire site over to a combination of css positioning and minimal utilization of tables. I haven't progessed to the point where I feel comfortable absolutely positioning everything on my page, but I will!

My hopes in starting this thread are to educate on the use of CSS1 (the basics) and now CSS2 (the basics). I emphasize the basics because I am no CSS guru, but I learn quickly. All of the imposing limitations that I had previously are now almost non-existent. Positioning of html was my most important area of optimization. Why? Because I started my career back in the spidering days.;) And I still feel that properly formatted html plays an important part in the overall optimization of web sites.

When I first viewed the page above, I got goose bumps. My <h1> tag starts right after the <body> tag. You can do no better using traditional optimization techniques! In fact, I'd be willing to bet that you'll find 1 out of 100 ordinary sites that have achieved this, most wouldn't know anyway. But, I'm sure there are many optimized sites that are also not utilizing this design method or strategy.

Could it really be a strategy? I don't know yet! But, from my six years of experience, along with my gut instinct, tell me that the few sites I'm building right now will rank a little higher than they would have using my previous methods. I say previous, because I am not turning back!

When I switched to using external css and js a few years ago, that was a big thing. I was able to minimize code bloat and provide a clean path to content. But, there were usually images that appeared before that content and that was always a problem. What do you do when you have 10-14 <td> tags with images in them? That question no longer plagues me. I now put them at the bottom of the html in a <div> tag whose position is being controlled by properties within my external CSS file. Here's an example...

This is my header <div>

<div class="header">
<!--webbot bot="Include" U-Include="navigation-2/top-class.htm" TAG="BODY" -->
</div>

Sorry, I even got a little fancy and used an FP include. You could also use SSI's (Server Side Includes).

Here is the css controlling the header <div>

div.header{
position:absolute;
top:0px;
left:0px;
width:750px;
visibility:visible;
}

This is my body <div>
<div class="body">King Content Here</body>

Here is the css controlling the body <div>

div.body{
position:absolute;
top:127px;
left:151px;
width:599px;
visibility:visible;
}

Now, go ahead and give it a try. Set up an external css file for testing. Build a simple page just using the header and body <div> tags and it will all click, literally!

Enjoy, I hope this will keep some of you awake as long as it has me over the past week. Payback!

highman
04-03-2002, 04:11/04:11AM
Pageone, playing this weekend with a site, removing tables and code bloat, I cam across a problem with absolute positioning;

I tend to use a footer include (SSI) if I put this include in a <div class=footer> tag how can I position the tag so its always at the bottom of the page?
The problem arises because on some pages the content could be two screens in length and on other pages it may only be 4 lines, in either case the footer div needs to underneath the content but at a min the bottom of the screen, this content is produced dynamicly so I cant build each page seperatly and position it using say {top 600px;}

Any ideas?

pageoneresults
04-03-2002, 10:02/10:02AM
Hello highman! I thought about that one too. I'll be doing more studying over the next couple of months (or should I say years) in regards to Absolute Positioning.

What I've done to work around that is just put my FP Include in with the main content of the page. Go to the home page of seoconsultants and view the source, you'll see what I mean. it works just fine and I really see no reason to use a <div> for positioning the footer, in my case anyway.

F-S
04-03-2002, 10:08/10:08AM
I'm looking for the most browser compatible means of 2 column text via css. Any suggestions?

highman
04-03-2002, 10:16/10:16AM
Yeh the problem I have with that is we use 3 columns, the center one being the main content. If I put the footer in with the main content then it will not span the other 2 columns......

Oh well back to research ;)

pageoneresults
04-03-2002, 10:19/10:19AM
Good morning F-S! Not sure that I can answer your question with any authority just yet. I'd need to see a page before I could offer some quality feedback.

What I might do is have two <div> tags; one that looks like this in the css...

div.column1{
position:absolute;
top:200px;
left:200px;
width:300px;
background-color:#ffffff;
visibility:visible;
}

And of course the <div> class would like like this...

<div class="column1">Insert Content Here</div>

div.column2{
position:absolute;
top:200px;
left:400px;
width:300px;
background-color:#ffffff;
visibility:visible;
}

And of course the <div> class would like like this...

<div class="column2">Insert Content Here</div>

Now, what you have above those two <div> tags is another story. It might look something like this to display a 760px wide header right above the two <div> tags with the two column layout.

div.top{
position:absolute;
top:0px;
left:0px;
width:760px;
height:200px;
background-color:#ffffff;
visibility:visible;
}

And of course the <div> class would like like this...

<div class="top">Insert Content Here</div>

Then you have that left column which will occupy the very left side of the page.

div.left{
position:absolute;
top:200px;
left:0px;
width:160px;
background-color:#ffffff;
visibility:visible;
}

And of course the <div> class would like like this...

<div class="top">Insert Content Here</div>

Now, since you are using the css to control the positioning of those <div> tags, you can put them anywhere you want between your <body></body> tags.

The above example would produce a page that has a 760x200 header with three columns underneath of it. A column at left that measures 160px wide, then two columns right next to it which measure 300px wide and have no height assigned to them. Only use the height attribute when you need to control height. Without it, the <div> will grow vertically to accommodate content.

pageoneresults
04-03-2002, 10:42/10:42AM
highman, there are two more values that you can use for positioning; relative and static.Relative positioning means that the position you specify for an element is relative to its natural position in the document's flow.

An example:

{ position: relative; left: 40px; top: 10px }
Essentially, when you use relative positioning, an element is positioned relative to where it would regularly be. As soon as you stop applying relative positioning, the flow of elements returns to normal, which can cause some overlapping problems.

In addition to positioning things as absolute or relative, you can also use a value of static. This simply means that the element will be positioned normally within the HTML as we're used to, with no special positioning applied to it whatsoever.If I get a chance before you do, I'll test these two values and see what they produce.

highman
04-03-2002, 10:52/10:52AM
Cheers, will have a play tonight, at the moment i have quite complex set of nested Divs which almost do it but not quite :rolleyes:

Also now fighting with NScapes interpretation of background images :mad:

Boy is the code coming down now! in fact my style sheet is bigger than my home page :D

mcfleet
04-03-2002, 11:27/11:27AM
Good morning.

I love the idea of moving sooo much to the style sheets, but how are you handling browsers that don't support css. When I look at logs, I still see people using old browsers.

I want my code to be smaller, but I don't want to forget about how it's being seen.

pageoneresults
04-03-2002, 11:37/11:37AM
Good morning mcfleet. There is a way to make the pages degrade nicely and I'm looking into that. Right now, I'm not worried about those using browsers that don't support css, the numbers are miniscule and for my beta testing period, its not a big issue, yet!

The resources I've been using say to add the attributes to your div tag that you have set in your style sheet. So, if you have a div that aligns center, you would insert the attribute like this...

<div class="top" align="center">

There is much more to learn. Right now I'm working with the basics until my feet get wrinkled and then I'm going to dive in!

P.S. What percentage of users do you see that are not using css?

F-S
04-03-2002, 14:15/02:15PM
Originally posted by mcfleet
Good morning.

I love the idea of moving sooo much to the style sheets, but how are you handling browsers that don't support css. When I look at logs, I still see people using old browsers.

I want my code to be smaller, but I don't want to forget about how it's being seen.

The way I look at it is this:
The standard has been established and has been supported by a majority of internet users. Now ask yourself about the remaining small percentage of users that rebel against change. Do you really think these people are your real customers? Why aren't they upgrading to current industry standards? Is it out of laziness, rebellion, cost, etc?

In the case of the SEO business, I'd be willing to bet that these people wouldn't accept your suggestions to change.

People who use old technology have grown accustomed to websites that don't look right in their browser. They either move on, or deal with it. They are the ones who aren't willing to change. They are the ones who are slowing the growth and potential of the majority.

I see no problem with creating a website that is as cross browser compatible as possible. On the other hand, to be too concerned with old-old browser versions, is giving in to someone who is rebelliously dragging their feet.

There are 2 voices out there....Which one will win?

MazY
04-03-2002, 18:22/06:22PM
I'm with F-S all the way on this issue.

It always raises a smug grin on my face when I see the Netscape stats going down on Google's Zeitgeist (http://www.google.com/press/zeitgeist.html).

Just admire that beautiful downward slope... :D

pageoneresults
05-03-2002, 00:58/12:58AM
I'll tell you what, NS4.7 has been my savior in this testing phase of CSS and Absolute Positioning. IE and NS6+ are just a little too forgiving when it comes to improperly nested elements within a page. Netscape 4+ is a great HTML validation tool!

I've been testing for the past week in IE, NS and Opera. The site looks identical on all three browsers and I'm proud to say that we now have 100% valid HTML and CSS on all the main pages (30). I converted 95% of the site this evening, I have a few more popup pages to convert but, we're there!

Thanks to my designer DJ who has been following a few of these threads in regards to CSS. Without his support graphically, it would have been a while longer before I understood the concept of Absolute Positioning. He utilizes Image Ready which is an excellent program for slicing and dicing your graphics and then exporting them as CSS (option). After I saw the code it generated when selecting the above option, it all clicked and I was on a mission to become the positioning guru. :)

My next test will be using relative and static positioning to address the footer <div> that highman brought up. I'll keep you posted!

highman
05-03-2002, 02:52/02:52AM
Pageone after a bit of research it would appear that its not possible to use the footer oprion yet, however it looks like its being adressed in css3

And your right NS4 is a good html / css validation tool even it does cause a certain amount of swearing ;)

pageoneresults
05-03-2002, 03:48/03:48AM
I tested one this evening and it worked. Set a class in your CSS like this...

div.footer {
position:relative;
left:???px; (do you have a left margin?)
width:760px; (what is the width of the footer <div>)
font-family:"verdana", arial, helvetica, sans-serif;
font-size:14px;
}

Now, position a <div class="footer"></div> right before your </body> tag or wherever it needs to be placed. What happens is the <div> now takes on a position relative to what is around it. If you had put a top:10px; line in the css, it would position itself 10px from the element above it, let's say it was a <p></p>.

Give it a try and see if that works. It worked for me, I think. I wasn't ready to set up the test page yet and did not save my work but I sure remember that footer being exactly where I wanted it to be based on the relative position.

F-S
06-03-2002, 09:15/09:15AM
I found this new CSS positioning software. It's in beta and soon to go final. I just downloaded it & have yet to play with it. It looks interesting though.

Layout Master - web page layout editor
http://www.westciv-downloads.com