I’ve been busy improving the way this site looks in smaller screen resolutions and windows. The technique I was using achieves vertical and horizontal centering by using absolute positioning and negative margins. If the window was too small for the content, it cut it off without giving you the option of scrolling to see it all.
So instead of using absolute positioning to center horizontally, I’ve now used the auto margin method. This is the best way, as it stops trying to centre the content when the window is too small. Originally when I’d tested this, it was still cutting of the the left side in Mozilla/Camino/Firebird, so I’d left it out as an option. I eventually discovered that all it needs is a ‘min-width’ value adding to the containing
to stop this. At last, most users can see the all content if they scroll.
Here’s the new CSS:
#horizon {
background-color: transparent;
position: absolute;
top: 50%;
left: 0px;
width: 100%;
margin-top: -200px;
text-align: center;
min-width: 900px;
}
#wrapper {
margin: 0px auto;
background-color: #fff;
position: relative;
text-align: left;
width: 900px;
height: 380px;
}
You’ll still need to use absolute positioning to get the vertical centering, and an outer
(#horizon in this case) in which to centre the content. (The position:relative in the #wrapper rule allows me to position everything inside it using position:absolute rather than floats). Min-width/max-width is one of those really useful CSS properties, that would help in designing fluid layouts – if only more browsers supported it.
I’ve also reduced the height of the main area so that it fits within most browsers at 800×600 with lots of browser chrome. All in all, its still not perfect, but its a lot better.
If you prefer, the other option is a ‘diet’ version of hicksdesign – a basic stylesheet, with larger type and a fluid layout (no scrolling DIV’s).
Finally, one thing I’ve discovered: To make it easier to edit lists where whitespace has to be removed to avoid extra line spacing (IE Win whitespace bug), use the ‘format’ utility in BBEdit. Switching between ‘gentle hierarchal’ (for editing) and ‘compact’ (when you’re ready to upload) has really helped me work with my large menu code where I use
and to layout the navigation.
A friend of mine, Jonathan Williams, has just set up an online portfolio so now you lucky folks can see just how good he is. He uses a mixture of natural and digital media to achieve his unique style – I love it, it’s so fresh and attractive. (His company name ‘Blazing Fruit’ comes from a poem by Roger McGough)
I am on holiday – honest. Its great, finally getting plenty of quality time with my family, and not thinking about work. I do like to keep in touch with the blogosphere though, and this week I’m able to use my in-laws broadband connection.
After all my excitement at working out how to do pure image based CSS rollovers, here’s a far better way that doesn’t need images to be preloaded! If you’re prepared to create your images in slightly unusual way, it looks like the way to go! (found on stopdesign).
Also, NetNewsWire 1.04 is out, and //hicksdesign is one of the ‘latest additions’ in the sites drawer. Thanks Brent!
Dave Shea recently mentioned some alternatives to Doug Bowmans Image Replacement Trick. Having tried one of these methods, I realised that it would really suit rollovers without the need for javascript. Whereas previously I’d only thought it was possible by A List Apart’s method, this way doesn’t limit you to using only using bitmap fonts. Its purely image based. Apparently, Dave already uses this for the rollovers on Mezzoblue (so I’m not claiming any originality here!)
So to test this out, I’ve added a rollover & homepage link on this sites logo, and an article on how to do image rollovers with CSS. As with all my ‘articles’, please let me know if you have anything add, dispute or change. I don’t pretend to be a CSS expert, but hopefully someone will find it useful.
Here's how a plain text link can be converted into a pure image rollover using only CSS. You can see the result on the site's logo.
If you're not already familiar with 'Fahrner Image Replacement', read Doug Bowman's article on Using Background-Image to Replace Text. This presented a guilt-free way of using images for titles, although it relied on a superfluous <span> tag to hide the actual text. Not really a concern unless you were an absolute XHTML purist. The bigger problem was with JAWS screen readers, that treated text styled with 'display:none' as invisible and skips it.
The Gilder-Pixy Method
The following combines 2 techniques - Tom Gilders text-transform and Pixy's no-preload rollovers. The former uses 'text-indent: -10000em;' to hide the text from view, while the latter changes the position of the background image, rather than loading a seperate image. This means that you have to create an image containing both states, like this. These methods avoid the need to use the Box Model hack, display:none or some convoluted route to preload the rollover state. Its small code, and the rollover is faster. Combining the 2 methods also allows you to use pure images, rather than the text link/background combination (such as A List Apart)
Here's the code that went into the HTML:
<div id="logo">
<a href="/index.php" title="click to go back home">// hicksdesign</a>
</div>
No presentational markup, its just a plain ol' text link. Here's the CSS to go with it:
#logo a {
text-indent: -1000em;
background: url(images/logo.png) no-repeat left top;
width: 64px;
height: 369px;
display: block;
overflow: hidden; /* For nested divs in Safari */
}
/* IE 5 hack \*/
#logo a {overflow: hidden;}
/* end hack */
#logo a:hover {
background-position: -64px 0px;
}
There are 2 changes to the original code. The addition of the display: block, as the <a> tag will be treated as an inline element rather than a block and nothing will show up. Also, if the rollover is placed inside an absolutely-positioned nested div, Safari throws up a huge horizontal scroll bar (presumably 1000em wide). The overflow:hidden stops this, but needs to be hidden from IE 5 Mac or else the image won't visible.
Pros and Cons
This method allows you to create image based rollovers, without any need for javascript. Not that javascript is evil, but there are several advantages to using this method:
- Substantially less code.
- Works in IE 5-6 Win/Mac, Opera 7, Mozilla/Firebird/Camino and Safari.
- Users without CSS, or those using a different stylesheet will see the just plain text link.
- Search engines place little importance on <alt> tags, but plain text links are good. I've been told that text styled with display:none doesn't count either, but I can't confirm this.
- Javascript rollovers need an 'onMouseOver' and 'onMouseOut' event adding to the <a> tag. Accessibility validators pick up on this and request that you supply an alternative with <noscript>. A bit of a faff quite frankly.
The only disadvantages are:
- If the user has CSS on, but images turned off to improve browsing speed, they'll see nothing. Ooops! Tom has a solution for this which requires an extra span tag.
- One other problem is a bug in Safari, where if you place the rollover in an absolutely positioned DIV the image doesn't revert back when rolling out. Fortunately, I was able to position the logo DIV with margins instead (and decrease the amount of code needed in the process! Sweet!)
Thanks to Tom Gilder and Pixy for creating these methods!
Further Reading:
Dave Shea has written an article on Fahrner Replacement for Digital Web Magazine.

More good news! I’m very happy, because my first submission for the CSS Zen Garden has been accepted and now up on the Zen Garden Site. Its called ‘entomology’, for reasons that will become obvious. If you use Camino/Mozilla, you’ll get to see everything, as there a few pseudo CSS elements that aren’t essential, but just add a little something.
The Zen Garden is a good challenge for CSS designers – you can only change the stylesheet (although the HTML page is well marked up) so it really hones your skills. I’ve learnt more about CSS selectors by doing this, and how they can really cut down on coding.
This is the website job that I would’ve sold vital organs to have worked on! The British Library now has a virtual tour of the Lindisfarne Gospels. With the wonder of shockwave, you can turn the pages of the 1000 year old illuminated manuscript by clicking and dragging (if you don’t turn the page far enough – it falls back).
The quality of the scanning is amazing, and the level of detail you can see with the magnify option is breathtaking. I won’t go on about how this was such an important work – go see for yourself!
Archives by tag:
2006,
2007,
accessibility,
acoustic,
actionscript,
adobe,
advert,
adverts,
advice,
air,
alternative,
ambient,
analog,
apple,
applecare,
appletv,
apps,
appstore,
art,
articles,
atmedia,
attap,
audio,
australia,
awards,
ban,
basecamp,
bbc,
belkin,
bitmap,
blackhole,
blogs,
bluetooth,
bonecho,
books,
boxee,
boxeebox,
boxmodel,
braindump,
britain,
british,
browser,
browsers,
browsers.mozilla,
bug,
bugs,
cairo,
cakes,
calendar,
camera,
camino,
casestudies,
cbbc,
cc,
chap,
chaps,
cheerup,
cheese,
childreninneed,
christmas,
cinelli,
cms,
cocoalicious,
coda,
code,
collections,
colour,
colourblind,
colourblindness,
comedy,
comments,
comps,
conferences,
copywriting,
cotswolds,
country,
covers,
craft,
cs5,
css,
css.webstandards,
cycling,
danielsmonsters,
delicious,
dell,
design,
design.colourblindness,
desktops,
digital,
discovery,
discussion,
dock,
doctorwho,
dogs,
drawing,
dream,
dreams,
dropbox,
drwho,
education,
electronica,
email,
emoticons,
england,
events,
evernote,
expressionengine,
eyetv,
family,
feedback,
femalevocal,
figures,
films,
firefox,
fireworks,
firstworldproblems,
flash,
flexible,
flickr,
flock,
fonts,
found,
foundries,
foundsounds,
fowd,
free,
frontrow,
ftp,
g5,
games,
gaming,
gardening,
garlic,
geek,
geekends,
geekery,
geekmediabox,
genius,
gentleman,
gifs,
gigs,
google,
googlereader,
grammys,
graphics,
greader,
grids,
gtd,
hacks,
handbag,
handbags,
hardware,
harrypotter,
helvetica,
helvetireader,
heros,
hicksdesign,
history,
holiday,
hosting,
howto,
html5,
humanrights,
icab,
ical,
ichat,
icon and interface design,
icon design,
iconhandbook,
icons,
ideas,
illustration,
illustration/icon design,
illustrator,
illustrators,
im,
images,
indesign,
infographics,
inspiration,
installation,
intel,
interface,
interfaces,
internet,
internetexplorer,
interview,
interviews,
inventions,
ipad,
iphone,
iplayer,
ipod,
itsmyblogandillbangonifiwantto,
itunes,
javascript,
jobs,
journal,
justabitoffun,
leaflets,
lego,
leigh,
lifeio,
links,
list,
listening,
lists,
littlebigplanet,
logo,
logo and branding design,
logo design,
logos,
london,
londonbombing,
mac,
macbook,
macmediacentre,
macmini,
macs,
macworld,
magazines,
magazines.illustration,
making,
maps,
mediacenter,
mediacentre,
mediacentres,
mellow,
memes,
menus,
merchandise,
messages,
metal,
microformats,
microsoft,
modernart,
moleskine,
monkeybutler,
movabletype,
movies,
mozilla,
music,
myob,
natural,
nerdery,
news,
nintendo,
nostalgia,
nostradamus,
notes,
obituaries,
office,
omniweb,
opacity,
opensource,
opera,
organisation,
os,
osx,
oxford,
oxfordgeeknight,
packaging,
panic,
panther,
paper,
parallels,
penguin,
people,
photo,
photos,
pimp,
pipes,
plex,
plugins,
png,
podcast,
polygamy,
posters,
powerbook,
practice,
presentation,
presentations,
presents,
press,
print,
printmaking,
productivity,
propoganda,
ps3,
published,
punditry,
questions,
quicksilver,
quotes,
radio,
radiohead,
raf,
railway,
rants,
rapha,
resources,
responsive,
retorts,
retro,
review,
reviews,
riffs,
rip,
ripoffs,
rissington,
rss,
safari,
saft,
sage,
samantha,
science,
scifi,
scrapbook,
scripts,
security,
server,
shelf,
shiira,
sideprojects,
signage,
simplenote,
sites,
siteskin,
siteskins,
sixties,
skinning,
skype,
slides,
slowcore,
software,
solutions,
songbird,
sony,
sound,
spam,
speakers,
speaking,
sponge,
spotlight,
starflyer59,
starwars,
stationery,
store,
summerboard,
surveys,
svg,
sxsw,
syncing,
tagging,
talks,
tea,
teasing,
templates,
ten,
texpattern,
text,
texteditor,
texteditors,
textile,
textpattern,
thebeatles,
theme,
themes,
theming,
thenational,
theory,
tiger,
timeline,
tips,
toys,
tumblr,
tv,
tweed,
typefaces,
typography,
ui,
updates,
updtes,
userstyles,
vector,
veer,
versions,
video,
vinyl,
vw,
wallpaper,
web,
webapp,
webapps,
webbies,
web design,
webfonts,
webkit,
website and logo design,
website design,
webstandards,
whitenoise,
why,
widgets,
wifi,
wii,
windows,
wireframing,
wishlists,
wordpress,
work,
working,
xhtml,
xul,
yojimbo,
youtube,
zengarden