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.
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!
No matter how you try and avoid it, you often get to the point where you need to hide CSS from a particular browser, because of a bug. Its 'not cricket' but they work, and they validate. So rather than being an article as such, what I've done here is gather all the various links for hiding CSS from browsers.
Please let me know if you find any more!
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.
For a long time I'd wanted to achieve a vertical centering effect with CSS that I used to achieve with tables or frames. A fixed size block that floats dead centre in the browser window, no matter what its size. Techniques for horizontal positioning have been known for some time, with the 2 methods described on Blue Robot. Then I found across a piece on Web Page Design for Designers, outlining how to do this. Nirvana! It uses absolute positioning to put find the exact centre point of the window, and then uses negative margins to 'shift it all back halfway', producing the effect. It works, but there are 2 problems with this:
the problems
- As the CSS technique uses absolute positioning with negative margins, if the browser window is smaller than the centered content, it crops it off without giving you scrollbars to access it. I wanted the site to get a long 'panoramic' style, but I also didn't want to exclude users with 800x600 resolution. The fact that some users couldn't even scroll to see content was a big problem.
- In Interner Explorer 5 for Mac, if an XHTML doctype is used instead of HMTL Transitional (as used in the Web Page Design for Designers article), the content gets uncereromoniously pushed off the top of the browser window. While IE5 Mac is being phased out now that development has been stopped, its still the main browser for OS 9 users.
the solutions:
the cut-off content problem
The WPDFD technique uses 2 container divs - #horizon for the vertical and #content for the horizontal. Originally, these 2 divs were needed due to a bug in Opera. While this has since been fixed in version 7, there is another use for the extra container div.
Instead of using absolute positioning to center horizontally, use the auto margin method to centre the second <div> within the first. This is the best way, as it stops trying to centre the content when the window is too small. This still cuts of the the left hand side in Mozilla/Camino/Firebird, but all it needs is a 'min-width' value adding to the containing <div> to stop this.
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 {
background-color: #fff;
position: relative;
text-align: left;
width: 900px;
height: 380px;
margin: 0px auto;
}
The addition of position:relative in the #wrapper rule allows me to position everything inside it using position:absolute rather than floats, which makes life easier and accurate. You may not need this however. This solves the problem of content being cut off horizontally.
As for the vertical - you just have to make sure that you specify a height that will fit in your target market's lowest screen resolutions. I used 380px, which should fit in most browsers at 800x600 (once you've allowed for all that browser chrome).
IE5 mac and the commented backslash hack
To solve the IE5 mac problem, you need to use the commented backslash hack. First you add your style rules to work in IE5 mac, then you add your real styles rules, beginning with a backslashed comment and ending with a normal comment. IE 5 Mac ignores everything between the 2 comments, and these override the previous rules, providing the centering effect for all the other browsers:
/* styles for IE 5 Mac */
#horizon {
background-color: transparent;
position: absolute;
top: 20px;
left: 20px;
}
/* following rules are invisible to IE 5 \*/
#horizon {
top: 50%;
left: 0px;
width: 100%;
margin-top: -200px;
text-align: center;
min-width: 900px;
}
/* end IE 5 hack */
#wrapper {
background-color: #fff;
position: relative;
text-align: left;
width: 900px;
height: 380px;
margin: 0px auto;
}
As we've already stated rules like 'position: absolute' in the first set of style rules, we don't need to repeat these, only redefine rules that we want to change. So far I haven't been able to replicate the vertical centering effect, but at least it centres horizontally.
Archives by tag:
2006,
2007,
2012,
accessibility,
acoustic,
actionscript,
adobe,
advert,
adverts,
advice,
air,
alternative,
ambient,
analog,
apple,
applecare,
appletv,
apps,
appstore,
art,
articles,
atmedia,
attap,
audio,
australia,
authenticjobs,
awards,
ban,
basecamp,
bbc,
beatles,
belkin,
bikes,
bikeshops,
bitmap,
blackhole,
blogs,
bluetooth,
bonecho,
books,
boxee,
boxeebox,
boxmodel,
braindump,
breakfastbaps,
britain,
british,
browser,
browsers,
browsers.mozilla,
bug,
bugs,
cairo,
cakes,
calendar,
camera,
camino,
casestudies,
cbbc,
cc,
chap,
chaps,
charity,
cheerup,
cheese,
childreninneed,
christmas,
cinelli,
cms,
cocoalicious,
coda,
code,
collections,
colour,
colourblind,
colourblindness,
comedy,
comments,
competition,
comps,
conferences,
copywriting,
cotswolds,
country,
covers,
craft,
cs5,
css,
css.webstandards,
cycling,
danielsmonsters,
delicious,
dell,
design,
design.colourblindness,
desktops,
development,
digital,
discovery,
discussion,
diy,
dock,
doctorwho,
dogs,
drawing,
dream,
dreams,
dropbox,
drwho,
education,
electronica,
email,
emoticons,
england,
events,
evernote,
expressionengine,
eyetv,
family,
favicons,
feedback,
femalevocal,
figures,
film,
films,
firefox,
fireworks,
firstworldproblems,
flash,
flexible,
flickr,
flock,
fonts,
found,
foundries,
foundsounds,
fowd,
free,
freelancing,
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,
hp,
html5,
humanrights,
icab,
ical,
ichat,
icon,
icon and interface design,
icon design,
icondesign,
iconhandbook,
icons,
ideas,
illustration,
illustration/icon design,
illustrator,
illustrators,
im,
images,
indesign,
infographics,
inspiration,
installation,
intel,
interface,
interfaces,
internet,
internetexplorer,
interview,
interviews,
inventions,
ios,
ipad,
iphone,
iplayer,
ipod,
itsmyblogandillbangonifiwantto,
itunes,
javascript,
jobs,
journal,
justabitoffun,
koken,
leaflets,
lego,
leigh,
less,
lifeio,
links,
list,
listening,
lists,
littlebigplanet,
logo,
logo and branding design,
logo design,
logos,
london,
londonbombing,
mac,
macbook,
macmediacentre,
macmini,
macs,
macworld,
magazine,
magazines,
magazines.illustration,
making,
maps,
mechanics,
mediacenter,
mediacentre,
mediacentres,
mellow,
memes,
memories,
menus,
merchandise,
messages,
metal,
metro,
microformats,
microsoft,
modernart,
moleskine,
monkeybutler,
moon,
movabletype,
movies,
mozilla,
mum,
music,
myob,
natural,
nerdery,
newmusic,
news,
nintendo,
nostalgia,
nostradamus,
notes,
obituaries,
offers,
office,
offscreen,
omniweb,
opacity,
opensource,
opera,
organisation,
os,
osx,
oxford,
oxfordgeeknight,
packaging,
panic,
panther,
paper,
parallels,
penguin,
people,
photo,
photography,
photos,
pimp,
pipes,
plex,
plugins,
png,
podcast,
polygamy,
posters,
powerbook,
practice,
presentation,
presentations,
presents,
press,
print,
printmaking,
productivity,
products,
projects,
propoganda,
ps3,
published,
punditry,
puppetry,
questions,
quicksilver,
quotes,
radio,
radiohead,
raf,
railway,
rants,
rapha,
recentwork,
repair,
resources,
responsive,
retorts,
retro,
review,
reviews,
riffs,
rip,
ripoffs,
rissington,
rss,
safari,
saft,
sage,
samantha,
sass,
sauce,
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,
startrek,
starwars,
stationery,
stevejobs,
store,
summerboard,
surveys,
svg,
sxsw,
syncing,
tagging,
talks,
tasks,
tattoos,
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,
videos,
vinyl,
vw,
wallpaper,
web,
webapp,
webapps,
webbies,
web design,
webfonts,
webkit,
website and logo design,
website design,
webstandards,
whitenoise,
why,
widgets,
wifi,
wii,
windows,
windows8,
wireframing,
wishlists,
wordpress,
work,
working,
xhtml,
xul,
yojimbo,
youtube,
zengarden,
zip