Beruflich Dokumente
Kultur Dokumente
css g
get the best
out of CSS3
Your essent ial CD
ll require
All the files you
al can be
for this tutori
issues CD.
found on this
Craig Grannelll turns into a cross between Jeffrey Zeldman and Russell Grant, taking a peek at
what the future of CSS has to offer – with a little help from Opera, Safari and Firefox
If the list has a half-dozen or more items, youll soon be wasting plenty of
space on screen. But apply a class to the list and use the following CSS and the
list will display over two columns:
.twoColumnList {
width: 40em;
-webkit-column-count: 2;
-webkit-column-gap: 1em;
-moz-column-count: 2;
-moz-column-gap: 1em;
}
Working titles
Style that adapts to every browser
An example of a site that works in any browser you care to shake
a stick at is dowebsitesneedtolookexactlythesameineverybrowser.
com. Answering the question posed in its URL, its single page (which
merely displays NO!) offers a slightly different visual design in various
browsers. For those with up-to-the-minute support, such as Safari 3,
the text has a drop shadow; for those left behind, such as IE6, the PNG
has a white background; and on different platforms, the font varies.
The point, of course, is that the minimal design remains usable even
when stripped of its more fine-tuned, design-oriented elements.
Multiplicity For lovers of liquid layouts, multiple backgrounds could soon make things
more interesting from a visual standpoint; only Safari currently supports them, however
Drop shadows are another recent addition to the arsenal of some browsers,
although the text-shadow property is actually part of the CSS2 spec, not CSS3.
Nonetheless, its worth mentioning here, not least because CSS3 now also
provides the ability to define a drop shadow on a box. First, however: text.
Four values are defined when using the text-shadow property, which
is currently supported by Safari and Opera. The first two values define the
horizontal and vertical distance of the cast shadow; the third value defines
the blur distance in pixels; and the fourth value is the colour of the shadow.
Therefore, the following CSS produces a fairly typical drop shadow that you
might use to draw attention to a heading:
text-shadow: 0 0 10px #ff0000; prefixes. Because content still reaches the edges of the box in question, it
makes sense to define a padding value thats at least equal to the border
Opera enables you to take things further. It supports comma-separated radius, as shown in the following code block:
value sets for text-shadow, enabling you to define multiple sets for a single
element. This means that you can cast a like-coloured shadow in several .roundedCorners {
directions to create a much larger, bolder glow effect. width: 300px;
Alternatively, you can mix colours, as shown in the red and blue blur background-color: #d3aa9c;
and flaming text examples depicted elsewhere. Code for all of these margin-bottom: 20px;
shadows is on this issues disc, in the file text-shadows.html. padding: 10px;
As mentioned previously, though, CSS3 now enables you to define a -webkit-border-radius: 10px;
drop shadow for a box, negating the requirement to use images. Currently, -moz-border-radius: 10px;
only Safari supports this, although we suspect other browsers will follow }
suit shortly.
The de-facto property is box-shadow, and this is currently applied in Of course, the various properties mentioned so far for boxes can be combined,
Safari using -webkit-box-shadow; the values to define are as per the text- so its easy enough to create a rounded box with a drop shadow. Usefully,
shadow rule. the drop shadow conforms to the rounded corners, as youd expect. An
example can be seen in the snappily named box-with-corners-and-shadow.
Smoothing the edges html document on this issues disc, which also highlights another addition to
Shadows are all very well, but we think border-radius is likely to appeal most CSS3: opacity. If you open the document in Safari, Firefox or Opera, youll see
to web designers – at least those infatuated by the current trend for all things a red semi-transparent rectangle overlaying the pages other div. The opacity
curvy. What this property enables you to do is set a radius for a boxs corners, is defined by the cunningly named opacity property; the value range is from 0
thereby enabling you to do away with JavaScript or image-based hacks. to 1 and affects all content within the element its applied to. Safari and Firefox
Currently, this works in Firefox and Safari, and requires the -moz- and -webkit- also enable you to define opacity by using RGBA values (the A standing for
alpha), and so you can, for example, define the value rgba(255, 0, 0, 0.3) for
One of our favourite additions background to create a semi-transparent red background on an object.
While on the subject of backgrounds, one of our favourite additions to
CSS3 is the ability to define multiple backgrounds for an element. Its
is the ability to define multiple common for web designers to use ugly (from a coding standpoint) hacks
to define multiple backgrounds for a web page or a content area, but in CSS3
backgrounds for an element you can comma-separate background values, thereby enabling you
to add and position as many background images as you please. For
example, to position four images, one at each corner of the pages create a page with two divs, each with a width of 50 per cent, and float them
body, you could use the following rule: both left. Now add some padding and a border of a fixed size to each. Theyll
stack underneath each other, because the combined content width now
body { exceeds 100 per cent. Various workarounds exist: you can define padding and
margin: 0; borders in percentages and ensure the sum of all the width values doesnt
padding: 0; exceed 100 per cent; you can ensure your div widths dont add to anywhere
background: near 100 per cent (providing space for padding and borders); or you can
url(bkg-tl.png) 0 0 no-repeat, create nested divs and apply borders and padding to them. However, CSS3
url(bkg-tr.png) 100% 0 no-repeat, enables you to use the border-box property value box-sizing to, for specific
url(bkg-br.png) 100% 100% no-repeat, elements, emulate the box model used by IE 5.5 and before. Currently, Opera
url(bkg-bl.png) 0 100% no-repeat; uses the property as-is, but Safari and Firefox need the -webkit- and -mox-
} prefixes. Ironically, versions 6 and 7 of Internet Explorer dont support this
property, although the current beta of 8 at the time of writing accepts -ms-
Currently, only Safari supports this means of adding backgrounds and an box-sizing. (See other-boxes.html for an example of this property in action.)
example, multiple-backgrounds.html, is on this issues disc (it requires the And thats not everything CSS3 has to offer. Weve mentioned just a subset
four PNG background images referred to in the previous rule). of the extras youll (hopefully) soon be able to integrate into websites. As well
as the properties mentioned there are, among others, resize, which is currently
Perfect positioning unsupported, but which will enable you to define whether an elements box can
The final property well look at is box-sizing, which dredges up an age-old be resized by the user; border-image, which enables you to define images for
argument about the CSS box model. Understanding this model is integral to element borders, rather than being restricted to a small set of lines and patterns;
CSS layouts. If youre not entirely familiar with it, it works something like this: and the ability to size background images (in Opera and Safari) via background-
in CSS, you define the dimensions of an elements content area; you can then size (using the -o- prefix for Opera and -webkit- for Safari) and define their point
add to that padding and borders. Therefore, a 100-pixel-wide element with a of origin as relative to the edge of an items padding or content via background-
10-pixel border will actually take up 120 pixels of horizontal space. origin (which accepts the values content, padding and border).
Before version 6, Internet Explorer disagreed, and instead placed borders It may seem premature to look at these properties now – as weve said,
and padding within the defined dimensions. Eventually, Microsoft relented certain properties only currently work in certain browsers, often also requiring
and the box model was fixed for IE6. The thing is, Microsofts old way of prefixes. However, it pays to know where things are likely to head in the
doing things was actually pretty useful in certain circumstances. For example, world of web design, and even if you dont consider dabbling in CSS3 getting
yourself ahead of the game, its still fun to experiment and know that youll be
able to bin a whole slew of hacks in the not-too-distant future.
Resources Where to find out more
List orders In the not-too-distant future, CSS3 will enable you to automatically display
elements in columns: handy for laying out lists of short items
Css3 Info World Wide Web Consortium
Everything you need to know For more information about the About the author
about CSS3 – at least, thats CSS3 specification – and, indeed,
Name Craig Grannell
what the strap-line says. To a any of the web specifications that
large extent, its right: this is an takes your fancy – nip over to the Site www.snubcommunications.com
excellent blog for keeping abreast World Wide Web Consortium Areas of expertise Information architecture, site concepts
of CSS3 news and information. website, and all will be revealed. Clients Swim~, Rebellion, IDG
css3.info w3.org What makes you angry? Things that dont work when
they should