It's the scrollbar, idiot!

Update: As Craig pointed out, the original version of my page flashed blue before changing orange. That was my bad. Here’s what was wrong, as an FYI:

Original Stylesheets:


<link rel="stylesheet" type="text/css" href="csdeptb.css" title="Blue Layout" />

<link rel="stylesheet" type="text/css" href="csdepta.css" title="Orange Layout" />

...

<body onload="setActiveStyleSheet('Orange Layout');">

The problem? Both stylesheets were loaded by default as preferred stylesheets, and since the blue sheet is listed first, it took precedence, rendering the page blue. Then on page load, I fired off a javascript call to set the orange sheet as active. This was to work around a weird IE glitch where it didn’t always load the second style sheet. BUT, this resulted in the page being blue until it fully loaded, and then changing orange. The solution? List orange first, and make the blue an alternate stylesheet, like so:


<link rel="stylesheet" type="text/css" href="csdepta.css" title="Orange Layout" />

<link rel="alternate stylesheet" type="text/css" href="csdeptb.css" title="Blue Layout" />

...

<body onload="setActiveStyleSheet('Orange Layout');">

[/Update]

So I’ve been having fun over the past couple days playing with HTML and CSS for a CS 640 (Intro to Computer Networks) assignment. The assignment is pretty trivial: basically, create the homepage for a fictitious Computer Science department. The home page should include 3 HTML documents (a home page, a faculty page, and a course listing), and two interchangible Cascading Stylesheets to play with colors. I put the shell of the page together pretty quickly, and then I’ve been spending some time playing with fancy CSS effects instead of doing my circuits homework 🙂

The page, for any who are interested, is located here: CCM University’s Computer Science Department

One annoying “bug” I kept running into was that my nicely-centered TABLE (yeah, I know… <TABLE>s are SO Web 1.0. Get over it.) kept shifting slightly to the right on the main page (index.html), and then back slightly to the left on the other two pages. I looked into this for probably 30 minutes, trying to find some extraneous tags or something that were screwing up the spacing.

(It’s a little hard to see on the thumbnails, but note the scrollbar appearing. The motion is easy to see in the fullsize pics.)

Main page (shifted right):

Faculty page (shifted left):

Then on one refresh, I noticed that the scrollbar appeared, and I slapped myself in the face. DUH. Longer pages (faculty.html and courses.html) –> don’t fit on one screen –> Need a vertical scrollbar –> Need to shrink the size of the content pane –> A centered element shifts to the left by half the distance of the scrollbar’s width.

My forehead hurts in shame.

To attempt to redeem myself, here’s a 30-second code snippet for centering stuff in CSS:

index.html

...

<LINK REL="stylesheet" TYPE="text/css" HREF="style.css" />

<BODY>

<TABLE class=framework> <!-- Desire to center this table -->

...

style.css

...

body { text-align: center; } // Center for IE

.framework {

     margin: 0px auto; // Center for Mozilla

     width: 800px;

     text-align: left; // Prevent IE hack from inheriting

}

...

4 thoughts on “It's the scrollbar, idiot!

Leave a Reply

Your email address will not be published. Required fields are marked *