Thursday, October 19, 2006 - Posts

Adventures in CSS: Stretchy Frame

One of the surprising CSS challenges for Windows Marketplace was stretching the spiffy "glass" frame to fit the content.  The visual design of the site is intended to suggest Windows Vista: a glassy frame in the center of the page around the content, yummy background gradients filling to the width of the browser, even the grassy texture behind the footer.   Despite the visual sophistication of such a design, it should be easy to layout, right?  I mean, with tables I could just slice those images up and make the pieces the background for various cells...

It sure seemed easier to do a table layout but doing so would have put a stake through the heart of the semantic web hopes for the website.  So we tapped CSS guru Robert Biggs for some help with this and other CSS challenges for the site.  Here's the technical breakdown of the stretchy frame problem, and how Robert solved it.

Requirements:

  • Vista-like glassy effects in IE6, IE7, FireFox 1.5+
  • Scales vertically to the content.  (Scaling horizontally was not a requirement)
  • Looks good on monitors with high resolution or wide aspect ratios.

Design:

The design called for two gradient background fills: one at the top and another at the bottom.  A fixed-width frame is centered on top of the gradients, which stretch for the width of the browser.  On high resolution monitors, instead of have the web content parked in the left side of the browser with a whole bunch of white space on the right, the browser frame is filled.  It looks really nice. 

As the frame stretches vertically, the white background between the two gradients increases.  The sides of the glass frame stretch over the white region as well, of course.

     

One constraint we needed to decide up front was the minimum height of the content region (the white region in the picture above): 700px.  This ensured the gradients would never collide.    Robert implemented the graphics to make both gradients blend to the center color.  In markup, he nested two <div> tags just inside the body.  He attached the top gradient image to the outer div as a background image, and the bottom gradient in the inner div as a background image.  This permitted the page to scale vertically as long as needed. 

Here's the CSS and markup -- it's pretty simple:

#bodyBackground { background-image: url(%img%/frame_elements/bkgd-gradient-top.gif); background-repeat: repeat-x; background-position: top left; }

#main { background-image: url(%img%/frame_elements/bkgd-gradient-bottom.gif); background-repeat: repeat-x; background-position: bottom left; }

#footerBackground { background-image: url(%img%/frame_elements/footer-bkgd.jpg); background-repeat: no-repeat; background-position: top left; }

</head>

<body>

<div id="bodyBackground"> 

    <div id="main">

        <div id="header">
          <!-- branding, menus, search -->
        </div>

        <div id="bframe">
          <!-- content region -->
        </div>

        <div id="footer">
          <!-- bottom search -->

          <div id="footerBackground">
              <!-- links -->
          </div>
        </div>

    </div>

</div>

</body>

 

The last challenge for the stretchy frame was the grassy texture behing the footer.   This texture is a background picture for the "footerBackground" div nested in the "footer" div (outlined in blue in the picture below).   Since the page sizes itself to the content, including footer content, this div is always at the bottom of the page.  The trick of pinning the bottom gradient to the bottom of the "main" div ensures that the gradient and image always line up perfectly.

 

 

Adventures in CSS: Windows Marketplace 2006

Often when you make the "sequel" to an existing application, several of the requirements boil down to fixing what didn't work well in V1.  For the original Windows Marketplace, one of the largest pain points was the lack of editorial control over just about everything: layout, style, content -- pretty much anything needed to keep the site fresh and compelling. 

So it's no surprise that one of the key requirements for the latest version of Windows Marketplace was lots of editorial control over just those things: layout, style, content, navigation, A/B testing, tracking, and all the other knobs the editorial staff needs to turn.  We made the call (some might say the leap of faith) to rely on CSS positioning for the core elements of the site, as well as CSS styles for much of the behavior of the site.  The content management system would emit only semantic markup; CSS would do the rest.

We had to learn quite a few CSS tricks to pull this off, but in the end using CSS has satisfied the editorial flexibility requirement with flying colors.

 

Home page with CSS:

Same page without CSS:

Source snippet (semantic menus):