Professional Documents
Culture Documents
Separate Content From Presentation: CSS Layouts
Separate Content From Presentation: CSS Layouts
5. Fast loading
CSS reduces the amount of tags used therefore producing clean code. Tableless
design can reduce your load time by 25% to 50%.
6. Reduce bandwidth
compacting the amount of code used will reduce the amount of bandwidth needed
to host your web pages. Therefore you won’t have to pay higher fees when adding
more web documents to your site.
7. Accessibility
increasing accessibility with CSS means being able to serve web content to a
larger audience, increasing web site usability, even for non-disabled people.
Content can easily be formatted for projection as well as screen display. Tableless
layouts display well on hand-helds.
divs
The <div> tag was designed specifically to take over from tables as a layout tool.
It is a block-level DIVsion element that can hold whatever you need inside it. You
can have blocks of text in divs and then put them together in a layout. You have
immense freedom, with the ability to add these blocks, or layers, on top of each
other.
The div tag has few attributes of its own, with all of its formatting applied through
stylesheets.
This example code uses some very simple CSS code. All block-level elements can
have a width property, specified in units or as a percentage, and then I just added
a background colour and some padding space around the div content.
The rest of the tags are inline elements. The rules which govern these two
element types are simple, but important:
Gecko - All Mozilla software, including Firefox; Galeon; Flock; also Epiphany
WebKit - Safari; Shiira; iCab 4; Epiphany; Adobe Air; Google Chrome; Midori;
OmniWeb; Adobe Dreamweaver CS4;
KHTML - Konqueror
Amaya - Amaya
Which Cascading Style Sheet (CSS) layout is best? All have their quirks and their
unique pros and cons. Is one more accessible than the other? More usable? What
are the drawbacks and how are they dealt with? Is one easier to create than the
other? Is there an evil, inaccessible layout? I suspect some will say yes to this, but
I’m not going to. I like them all and feel all are suitable if steps are taken to ensure
easy usability and equal accessibility. All are part of a web site’s presentational
layer, so most of the accessibility relies on the extractable semantics and proper
usage of the underlying mark-up. What follows is my take on the rigid fixed, the
adaptable fluid, and the expandable elastic layouts.
Fixed width layouts are sometimes easier to style depending on the effect you’re
after. Some visual designs can only be achieved in a reasonable manner with a
fixed width layout.
Based on the example width above — 760 pixels — the typical main content area
will be in my opinion an ideal width for optimum readability.
The Fixed Width Cons
People with small monitors (640×480 pixels) will end up with a horizontal scroll
bar on a 760 pixel fixed width site. This is a very uncommon problem.
A 760px fixed width site can look too narrow on large screen displays.
The narrow width can limit the reasonable number of columns and content, but
this may actually be a pro. Think forced moderation.
Fluid widths match the browser default layout method making this the “purist” of
them all. But does a developer’s want of site purity sometimes stand in the way of
usability? I think it may.
The fluid layout makes the most out of available screen real estate. More content
should be above-the-fold (meaning it’s available without scrolling in any
direction).
If width limiters using the CSS property max-width — which isn’t supported by
Internet Explorer (IE) version 6 or older, by the way — aren’t supplied, you may
very well, in your quest for layout purity, create a site that is at best difficult to
use. Try reading a line of text that is over 1000 pixels wide and you’ll begin to see
the problem.
Elastic Layouts
An elastic site’s main wrapper and other elements are measured using ems as the
unit of measure. Ems are relative proportionally to the text or font size. Thus, as
the text size is increased, the sections measured in ems will increase in size as
well.
An elastic layout is challenging and cool as hell. The first time I saw one was
Tommy Olsson’s site (which happens to be an exceptionally well done example of
how an elastic site should be done). This blew my mind, made me laugh, and
generally impressed the hell out of me. Elastic width sites are best enjoyed by
enlarging the text using ctrl and mouse scroll wheel… let me hear you say
“Zwoop.”
Unless limited, this layout method can be a usability disaster as it’ll get wider and
wider and wider — without benefit.
Hybrid Layouts
Hybrid layouts use a combination of fixed and liquid elements.
A hybrid layout where the header and footer are set to full percentage width and
the content is set to a fix width, a very popular layout in today's websites.
Positioning
absolute pulls an element out of the normal flow of the HTML and delivers it to a
world all of its own. In this crazy little world, the absolute element can be placed
anywhere on the page using top, right, bottom and left.
relative is much like static, but the element can be offset from its original
position with the properties top, right, bottom and left.
The value static is the default value for elements and renders the position in the
normal order of things, as they appear in the HTML.
fixed behaves like absolute, but it will absolutely position an element in reference
to the browser window as opposed to the web page, so, theoretically, fixed
elements should stay exactly where they are on the screen even when the page is
scrolled. Why theoretically? Why else - this works great in browsers such as
Mozilla and Opera, but in IE it doesn't work at all.
#navigation {
position: absolute;
top: 0;
left: 0;
width: 10em;
}
#content {
margin-left: 10em;
}
<div id="navigation">
<ul>
<li><a href="this.html">This</a></li>
<li><a href="that.html">That</a></li>
<li><a href="theOther.html">The Other</a></li>
</ul>
</div>
<div id="content">
<h1>Ra ra banjo banjo</h1>
<p>Welcome to the Ra ra banjo banjo page. Ra ra banjo banjo. Ra ra banjo
banjo. Ra ra banjo banjo.</p>
<p>(Ra ra banjo banjo)</p>
</div>
Floating
Floating an element will shift it to the right or left of a line, with surrounding
content flowing around it. Floating is normally used to position smaller elements
within a page