No Mod Required

Archive for the 'css' Category

CSS Variables - My Positive Feedback

I really like the idea, especially for "skinnable" apps and sites. We have a few ongoing concerns here that would immediately benefit from an @variables declaration after the reset section. Coding certain large changes, of course, would also be greatly simplified. Count me as a +1.

Initially, I do wonder about rendering performance since there are issues with IE's CSS Expressions and this seems like it could run into similar issues- then again I'm not a browser developer, so what the hell do I know? :)

Since the release of CSS Level 2 Recommendation ten years ago in may 1998, the Web authors' community has been requesting a way of defining variables in CSS. Variables allow to define stylesheet-wide values identified by a token and usable in all CSS declarations. If a value is often used in a stylesheet - a common example is the value of the color or background-color properties - it's then easy to update the whole stylesheet statically or dynamically modifying just one variable instead of modifying all style rules applying the property/value pair. We expect CSS Variables to receive a very positive feedback from both the Web authors' community and browser vendors.

CSS Variables

A New Site I Made is Live: Invesra.com

Check it out.

Invesra | Invest in your Future

The company is called Invesra. It's a financial services startup with backing from Village Ventures. I did a quick site for them to get their new brand* out the door for the FinovateStartup even in San Francisco this week. They've got a great team** and an interesting product so it's been a pleasure helping them out during a crunch period. As it always does, working with a startup makes me miss those startup days myself.

Then I think back to what working for two at once was like (Boston's Weekly Dig and Advisortech) and I like the agency life just that little bit more :)

*Tom O'Keefe's excellent work

**My lovely and talented girlfriend is Director of User Experience

I Just Signed up for CSS Naked Day

My site was born ready for CSS Naked Day.

Check the hot, naked screen captures

naked.jpg

Using overflow:auto to Clear Floated Content in CSS

For a long time, I used something like <div style="clear:both"></div> or its class equivalent to clear floated content in layouts. I knew, at some level, there were better solutions, but as these things go- I had deadlines to meet, had a working solution and there was never any inducement to look for a new one. Sure, there was a little extra markup, but it was so limited I could live with it.

Then in a comment on another post here ArkRep gift wrapped a better solution- one I vaguely knew about but had never explored. It looked a little something like this:

.clr {
clear:both;
}
.clr:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clr {display: inline-block;}

Liking it, since it swapped the useless markup hack thingie for a single class, I took a modified version of his code and moved it into our baseline screen.css at work. I then passed along the addition to the rest of the team. One of them (hi Ryan*), started to do some research into the code above and as an adjunct of that research came across a solution to the problem that was so simple and so clean that it really annoyed me that I didn't know about it until last week. You can read about the solution in depth at the Sitepoint Blogs (3 years old!)

The simple and clean solution? Use overflow:auto on the containing div and it will, er, contain. Look at this simplified version:

Here's the relevant CSS:

#container #content {
	overflow:auto;
	border:1px solid gray;
}
#container #copy {
	width:140px;
	border:.1em solid #CFCFCF;
	float:left;
	border:1px solid green;
}
#container #sidebar {
        width:140px;
	overflow:auto;
	float:right;
	blorder:1px solid pink;
}
#container #content #sidebar #sidebar-0{
	float:left;
	border:1px solid orange;
	}
#container #content #sidebar #sidebar-1{
	float:right;
	border:1px solid purple;
	}
#container #content #sidebar #sidebar-0,
#container #content #sidebar #sidebar-1 {
	width: 65px;
}
#container #footer {
	border:1px solid black;
}

I wish there was more to write about, but it's really that simple. The biggest concern is that your math must work or else you'll get scrollbars. With other versions of clearing floats, you were allowed to be a little looser with the calculations- if your sidebar actually leaked (overflowed) into the gutter beyond the edge of your container it didn't actually matter since it would display correctly. With overflow:auto you don't have that luxury. Of course, who wants to be sloppy? :)

*link? Where should I link?

A New Site I Made is Live and I Have (nearly) Achieved CSS Nirvana

I recently did CSS/HTML and WordPress theming for Tom's My Card. My Work. blog. Normally, I would get all that excited about a WordPress theme, since I've done several, but this one had a lot going for it from a CSS perspective. I'm actually really excited about it.

What's so special about this one, you ask?

Well, for starters, there's only one style sheet (1!) and in that one style sheet there's a total of 0 (zero) rules included for a specific browser. It's true. Actually, as the last step before I published it out to his server I deleted the lines in my template to pull in an IE6 or IE7 sheet. They were empty :) Across everything else? It just works. No hacks. No weird code. No nothing. Just one style sheet that works in pretty much every major (and minor) browser. I mean it, too- I tested the home page* in Browsercam and it only really fails on browsers that I don't care about at all- IE5.2 on the Mac, Netscape 4.78, IE5.0 and IE5.5, etc.

I have seen the future**, and it is one style sheet with no hacks.

Hallelujah.

In fact, when coupled with another technique I used for the first time in this layout (using overflow:auto to clear floats) and the fact that it's fully em-based and scales like a dream, this layout is probably the cleanest I've ever done- at least in terms of CSS.

Some time soon I'm going to clean the markup up further to get it in line with the level of the CSS in terms of cleanliness (I didn't fully craft every line in the theme, using some default markup in places,) re-skin it and publish it out as a theme for folks to download. That'll be pretty sweet.

Beyond that, which is going to take a little while so I've got to do something to tide you all over, I'm going to detail some of the techniques at play in the layout later on this weekend, starting with a head-slapping, *doh* filled post about the magical powers granted by my newfound knowledge of overflow:auto.

overflow:auto!

*Bugs will shake out in both the home page and other pages. I know this.

**Frighteningly it fails in IE8 beta, but then again it is a beta (fingers crossed)

Acid3 Test Released. I Took Some Screen Captures. Lots of Fail.

Screen Shots

[update! 3-27-2008] As everyone now knows, we've had a winner in the race to pass Acid3. Congrats to the WebKit team

acid-3-passed.jpg

These were done with browsercam, so the test may or may not have fully run its course by the time the 15 second delay was up. Still, it's not like any of these browsers were close, so a few seconds isn't going to save them if, in fact, they were cut off before the rendering was over.

As a note, I tried to do the Capture in Konqueror and it pretty much made Browsercam cry and/or vomit ("Do NOT Try The Capture Again!") I'm going to log in shortly to see what the actual damage is.

[update]It's a known bug[/update]

Reference Rendering:

reference-rendering.png

And now the Fail parade:

Camino 1.51 Mac OS 10.5

camino-151-mac.png

Firefox 2 Mac OS 10.5

firefox-2-mac-105.png

Firefox 3 Mac OS 10.5

firefox-3-mac.png

Internet Explorer 6 Windows XP

ie-6-xp.png

Internet Explorer 7 Windows Vista

ie-7-vista.png

Internet Explorer 7 Windows XP

ie-7-xp.png

Firefox 2 Windows XP

firefox-2-xp.png

Firefox 3 Windows XP

firefox-3-xp.png

Safari 3 Mac OS 10.5

[update]as seen in the comments the latest build is now scoring 87/100[/update]

safari-3-105.png

[update]Sorry Opera! I had the capture, but forgot to post it in my rush to get out the door today[/update]

Opera 9.24 Windows Vista

opera-924-vista.png

Here's Konqueror built from SVN 2008.03.06 (thanks to Ronald Hummelink and everyone else that sent in Konqueror captures)

acid3_konqueror_20080306.png

And here's IE8 Beta:

ie8-acid3.png

Opera 9.5:

acid3-opera-95.jpg

Firefox 3 Beta 4 on Windows XP

firefox-3-beta-4-acid3.jpg

Now, the press release:

Acid3: Putting Browser Makers on Notice, Again. - The Web Standards Project

Acid3: Putting Browser Makers on Notice, Again.

Released: 3 March 2008 | Author: The Web Standards Project

The Web Standards Project (WaSP) today announced the release of Acid3, the latest in a line of tests designed to expose flaws in the implementation of mature Web standards in Web browsers. By making sure their software adheres to the test, the creators of these products can be more confident that their software will display and function with Web pages correctly both now and with Web pages of the future.

The Acid3 Test is designed to test specifications for Web 2.0, and exposes potential flaws in implementations of the public ECMAScript 262 and W3C Document Object Model 2 standards. Collectively known as DOM Scripting, it is these technologies that enable advanced page interactivity and power many advanced web applications such as web-based email and online office applications.

As a series of 100 mini-tests, Acid3 has already been found to expose flaws in all tested browsers, including Internet Explorer, Firefox, Opera, and Safari. WaSP hopes that Acid3 will prove useful to browser makers during the development of future versions of their products.

WaSP has a history of such initiatives. In 1997, emeritus member Todd Fahrner, together with a group of crack Web developers dubbed the “CSS Samurai,” created an “Acid Test” that highlighted shortcomings in browser support for CSS. The Acid Test was instrumental in moving the industry much closer to the goal of consistent rendering of Web pages in different browsers. This was followed by Acid2 in 2005, designed to expose flaws in the implementation of mature Web standards such as HTML, CSS, and PNG. Acid3 builds on and extends this legacy to web applications in 2008.

Acid3 can be found online at http://www.webstandards.org/acid3/

An Old/New Site I Made is Live

If you're feeling nerdy, you can check out the long-neglected comic book blog I run. It's been redesigned and moved into Wordpress, which means I'm more likely to update it than I was when it was on Blogger.

The design is a "knocked out as quick as possible" special. I'll be tinkering with it over the next few weeks until I'm fully happy with it. I just wanted to get it out there. It's a full Wordpress site now, which is really the fun part- Valid HTML; a YSLow score in the upper 70s; easier to update; a fancy new sprite; S3 integration for all those cover scans…

What's not to love?

Click. If you dare!

It’s All Just Comics

Two Columns of Variable But Equal Height Using Simple CSS and a Couple of DIVs

If, like me, you cut your web development teeth during while CSS was still in its infancy, you likely put together a lot of sites that featured two (or more) columns decorated with bgcolors or background images that flowed together in lockstep, always retaining equivalent height. It was pretty standard and basically came along free with tables for layout.

Then? Along came CSS, the separation of style and content (don't forget behavior!) and the two columns living in perfect harmony became a casualty of the war against crufty code.

Which brings us to this post. I've played around with a similar technique before, but I'd never taken it to this, it's logical conclusion. This technique grew out of some conversation at work. I don't remember the specifics, but I remember I was looking at some unrelated piece of code on someone else's monitor. Walking back to my desk it reminded me of one thing or another and then the pieces started to tumble around in my head. It was a couple of hours later, on my drive home from work, when they clicked into place and I thought, "hey, I could fake that old technique!"

The basic idea goes a little something like this: just because a background color or gradient appears to be part of an element, that doesn't mean it needs to actually be applied directly to that HTML element. Instead, using some basic CSS and a repeating background image we can fake that two column look by positioning the two columns on top of the "columns" formed by the background image . As long as the containing DIV grows with either of the columns and the gap in the background image matches the background (or is transparent, wlloing the background to show through) the illusion is maintained.

It's like magic.

Here's the sample (which I only tested in FF2 and IE7):

Here's the CSS:

/*the two-column container*/
#container #two-columns {
	/*set that background image*/
	/*repeat it and center it*/
	background: url(images/bg.jpg) repeat-y center;
	height: auto;
	width: 500px;
	margin:auto;
	margin-bottom:20px;
}
#container #two-columns #column-2 {
	/*float it*/
	float:right;
	height: auto;
	width: 215px;
	padding:5px;
}
#container #two-columns #column-1 {
	height: auto;
	width: 215px;
	padding:5px;
}
/*clear the above float*/
#container .clr {
	clear:both;
}

and here's the HTML:

<div id="two-columns">
<div id="column-2">   A column in structural engineering is a vertical structural element that transmits, through compression, the weight of the structure above to other structural elements below. </div> 
<div id="column-1"> A column in structural engineering is a vertical structural element that transmits, through compression, the weight of the structure above to other structural elements below.  </div>
<div class="clr"></div>
</div>

I told you it was simple. If you're familiar with modern layout techniques the above should be commonplace. The interesting bit (to me at least) is the concept of pulling the "background" of the two columns off of the columns themselves and onto the containing DIV. This separation can be a powerful technique. I've used it before in a different context, but I think this example really illustrates how useful it can be. I'm already starting to see other possibilities for this pattern.

Expanding the toolbox is fun.

Of course, before I can actually use this technique where it's most needed by me, I have to come up with a scheme that works with both variable width and variable height. Tricky stuff. If I can pull that of, I'll install it right on my home page. As it stands now I'm using JavaScript to equalize the heights on the two news DIVs at the bottom.

Boo.

The good news is I've actually made some progress with the variable width/height version. Unfortunately, nothing is quite ready for prime time though so that'll have to be unveiled in another post. Keep your eyes peeled and your fingers crossed. I'll keep at it with the typing.

Two CSS Techniques I Love + I Rolled My Own Social Bookmarking Component

I used to use AddThis for social bookmarking here on the blog. And by "used to" I mean up until two days ago :-). Over the past couple of days I've been working on setting up my own version to use here and throughout the rest of the site. I launched it yesterday.

If you're on the single version of this post (as opposed to a category index or the blog home page) you should see it in all its simple glory below in the post info box.

Why bother since AddThis does what it's supposed to do and is dead easy to implement? Well, while the number isn't really important (only the underlying performance issues it uncovers really matter) it was pointed out recently that I (used to) get a 61 YSlow score for my blog pages (thanks Ben!) One of the contributing factors to that was the use of the AddThis widget which added another domain lookup and several extra HTTP requests for uncompressed files with no expires headers. I looked at all that overhead and inefficiency, looked at the functional complexity (or lack thereof) of the piece and decided I would just roll my own. Beyond the fact that it was just a fun little thing to do, doing my own saved 16 HTTP requests (including 13 Images,) removed a domain lookup and required a total of 0 (zero) extra files to implement. How? I obviously used my existing JS and CSS files and (most importantly) added the icons to my sprite. Those already come along with the page so it's just an extra 1-2K of image and script on top of my existing site infrastructure.

I didn't do anything particularly fancy (there's always time for that later :)), but if you're curious here's the basics of the implementation.

Here's the WordPress code, where we use the_permalink() and the_title() to build out the links:

<div class="shareThis">
Share This :  <a href="http://del.icio.us/post?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="delicious" title="save to delicious">Del.icio.us</a>
<a href="http://digg.com/submit?phase=2&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="digg-this"  title="digg this!"> Digg</a> 
<a href="http://reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" class="reddit"  title="submit to reddit">Reddit</a> 
<a href="http://www.stumbleupon.com/submit?url=<?php the_permalink();  ?>&title=<?php the_title(); ?>" class="stumble"  title="stumble this!">Stumble It</a> 
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();  ?>&t=<?php the_title(); ?>" class="facebook"  title="share on facebook">Facebook</a>
</div>

I chose those five because they were (a) amongst the most popular choices I saw in my AddThis stats and (b), with the exception of Facebook, they have all produced serious traffic spikes here. Facebook has never actually driven a lot of traffic for me, but it was a regular option in AddThis so I included it here.

As for the markup- as you can see, it's pretty stripped down. All I use are some anchors and a div to hold them. I then use a couple of common (for me) CSS techniques to get that stripped down markup styled up correctly. Here's the CSS:

.shareThis {
font-size:85%;
font-weight:bold;
color:#666;
background: url(http://media.drunkenfist.com/img/sprite2.png) -315px 0 no-repeat;
/*set position to relative in order to 'catch' child nodes at this level*/
position:relative;
padding:2px;
border:1px solid #ccc;
width:175px;
height:15px;
margin:auto;
margin-top:5px;
}
#moviespg  .shareThis,
#grafpg .shareThis,
#comicspg .shareThis,
#artpg  .shareThis{
/*there's a slightly different context for this widget on the rest of the site*/
font-size:75%;
}
.shareThis a {
/*I love absolutely positioned anchors with display:block*/
/*I use them all the time*/
position:absolute;
width:15px;
height:15px;
/*hide the text*/
/*I might switch this to opacity if the outlines bug me*/
text-indent:-9999px;
top: 2px;
}
/*position the individual anchors on top of their icons*/
/*this is like a new style 'image map'*/
.shareThis a.digg-this {
left:92px;
}
.shareThis a.delicious {
left:110px;
}
.shareThis a.facebook {
left:165px;
}
.shareThis a.reddit {
left:129px;
}
.shareThis a.stumble {
left:147px;
}
.shareThis a:hover {
/*hide the default hover since it obscures the icon*/
background:transparent url() !important;
/*safari didn't like the above, so I threw a little opacity in there*/
opacity:0;
}

I'll break out two of my favorite techniques in play.

Position:relative with no offset and absolutely positioned child nodes

The key with this technique lies in the behavior of absolutely positioned elements and the way that relatively positioned elements behave when there are no position coordinates (top, left, right, bottom) supplied.

Absolutely positioned elements search for the first parent element with a position other than static to begin to calculate it's positining. In the above example that's the containing div. The thing is, the containing div, while set to position:relative, has no offset coordinates supplied to it, which means it behaves exactly as if it were the default, static positioning. In other words it's still firmly in the normal flow of the document.

In the situation above the benefits of that might not be all that evident, but imagine this layout:

so-easy.png

With the middle content div set to position:relative and the two sidebars set to position: absolute inside of it, that layout can be achieved with a minimum of fuss. The header, content and footer DIVs are just in the normal flow. They will expand and contract as needed and won't need any special handling to grow as long as might be needed by the site content or any conditional messaging. The content DIV is set with enough internal padding set to accommodate the sidebars and the sidebars, as long as they don't need to control the height of the document, can be placed with pixel perfection wherever they need to go. No need to mess with floated content or anything fussy like that. Just two nice and stable absolutely positioned elements mixed with a normal block item document flow that would have worked in 1999. That layout will produce very few surprises.

Of course, if the layout requires two or more of the columns to be able to control the height then this technique is invalid, but if it's as simple as the one above, go nuts.

Another place I use that technique is with headers or mastheads. Headers often have three elements- a logo, a main menu and a utility menu. With that layout I will use a relatively positioned div for the container and then place three absolutely positioned items inside for the three elements: an image replaced header (h1, h2) for the logo, and two unordered lists for the two menus. The markup might look something like this:


<div id="header">
   <h1><a href="/" title="return to the home page">Our Company Name</a></h1>
   <ul id="main-menu">
      <li>menu item</li>
      <li>menu item</li>
      <li>menu item</li>
   </ul>
   <ul id="utility-menu">
      <li>menu item</li>
      <li>menu item</li>
     <li>menu item</li>
   </ul>
</div> 

And would render something like this:

common-header.jpg

So straightforward and it allows me to move things around with perfect precision.

Modern "Image Maps"

This ties in with the above but focuses entirely on using anchors as absolutely positioned block level elements to create "hot spots" in much the same manner old school image maps do. In the High Performance Web Sites book, Steve Souders talks about talk about using image maps to reduce HTTP Requests. While from a performance perspective that's a valid approach, image maps as a whole are out of favor and are rarely (if ever) a technique I'll look to use.

The following is a somewhat more accessible, SEO friendly method of achieving the same result.

A note about the example above, before I point out one that's a little more along the lines of my normal usage of this technique.

While I definitely like to use unordered lists as a container for menus and the like, there are plenty of situations where there's really no need for a containing framework. While in this example you could make an argument that I should have a list around the links (it's a list of links after all,) my first concern with this component was to create something really stripped down code-wise. I was trying to improve performance after all, so I went with the least code possible, sacrificing some potential semantic meaning in the process.

If I weren't flexible about these things I'd have to quit my day job and go work for a standards body :)

Anyway, the following image and code sample will outline a really useful implementation of this technique.

Here's some HTML:

<div class="messaging">
     <h2>The Toughest Challenges, The Most Interesting Ideas</h2>
     <a href="/register-now">register now</a>
</div>

Here's some CSS:

#copy .messaging h2 {
text-indent: -9999px;
height: 211px;
width: 778px;
position:relative;
}

#copy .messaging a {
position: absolute;
display:block;
text-indent:-9999px;
left: 200px;
top:150px;
height:28px;
width:140px;
}

And this is what it all looks like:

anchor-highlighted.jpg

As you can see with the red highlight, the absolutely positioned anchor perfectly fits on top of the hot spot, just like an old school image map; except in this case the meaning of the link is clearer in a text browser or to a search engine spider than it would be just using an image maps alt attribute.

Cool stuff.

To me at least…

I might actually turn this into a WordPress plugin, by the way. I'm like 25% of the way there already. Not that we actually need another one of these things of course. I'd do it just for the pure enjoyment of creating a nice solid piece of code that can be used around the internet. If I do, I'll document the whole process here :)

Why Did I Never Try this Before? CSS Font-Size : 0 Hides Input Button Text

Support: This technique is supported by IE 5.+, Firefox (and the rest of the Mozilla family) and Safari 3.0*. It is not supported by Opera** (any version), Netscape 6.2 and earlier or Camino.

Warning: I haven't thought this all the way through, so if you see any problems with this technique other than the above support caveats, then please let me know :) I'm really just writing this up because I just thought of doing it, I tried it and it worked…

The issue and solution: Occasionally I need to use an image, with text, for the background of an input button. It's rare, but occasionally it needs to happen. Thing about that is, I still want to have a regular value in there so that screen readers and people surfing without CSS at all can still figure out what the input says. I've usually encountered this issue on on fast-paced, get-em-out-the-door projects, so I've never had time to actually sit down and think about a solution. I've never actually come up with a solution that I liked for this. Negative text indent doesn't work, so I've always done random hacks to get it to work correctly. Recently I achieved it by shrinking it way down and coloring it the same size as the background.

Painful.

Today, for whatever reason, I took it one step further and set font-size:0;, hit F12 and saw, *GASP*, it worked. Browsercam verifies that it works for the above named browsers.

Here's a sample:

And here's the code for the above #go button.

#go {
	background: url(images/go.jpg);
	height: 25px;
	width: 41px;
	font-size: 0px;
        border:0;
}

This is one of those things that seems so obvious in hindsight. I just never thought to do it before today. hrm.

*Safari 1.2 and 2.0 ignore both the font-size AND the background image.
**Opera displays something like 6pt type.