Is this your first visit? You may want to subscribe to the feed.

Articles tagged with css

Showing Ajax activity with CSS

You know when you have a form that submits with Ajax, and you want to show some type of activity on the form? There’s several ways to do this, like including a hidden image that you show and hide while there is activity, or inserting and removing an image with javascript. These all just feel too dirty to me. I don’t want to have to change the markup just because the form is submitting via Ajax.

As usual, there’s a cleaner way to do it with just CSS. I’ve used this simple but effective trick on a couple projects now, so I thought I would share.

First, here is a demo of what it looks like: (sorry, you’ll have to leave your feed reader.)

Click the save button.

or Cancel

This technique is very simple. It adds a class on the form with Javascript while it is loading, and then removes it once it’s done. The loading class hides the submit button and replaces it with a background image, usually an animated gif.

First, with Javascript, add a class to the form while the Ajax request is loading. It would look something like this in Prototype:

$('my_form').observe('submit', function(event) {
  event.stop();
  this.request({
    evalScripts: true,
    onLoading:  function() { this.addClassName('loading'); }.bind(this),
    onComplete: function() { this.removeClassName('loading'); }.bind(this)
  });
});

Next, wrap an element around your buttons or whatever you want to hide.

<form>
  <div class="buttons">…</div>
</form>

Lastly, there’s just a little CSS to hide buttons and any elements inside them, and set the background image:

form .buttons { text-align: center; }
form.loading .buttons {
  text-indent: -2000px;
  overflow: hidden;
  background: url(../images/loading.gif) no-repeat center center;
}
form.loading .buttons * { visibility: hidden; }

There you have it. It’s really simple, but it’s worked well.

Code: css, CSS Mar 04, 2009 ● updated Mar 03, 2009 1 comment

Safari bug with DLs and floats

I came across a weird Safari bug today and couldn’t find any other mention of it on the interwebs. Here’s the CSS and HTML to reproduce it:

dt {
  width: 200px;
  float: left;
}
dd {
  margin: 0 0 0 200px;
}
dd p {
  float: left;
}
<dl>
  <dt>term</dt>
  <dd>
      <p>p1</p>
      <p>p2</p>
      <p>p3</p>
  </dd>
</dl>

With Float

What’s happening is that safari is adding a right margin to the dd, even though it is explicitly set to 0. Removing either the float: left from the dt, or position: overflow from the dd (which is used to clear the floats) makes the right margin go away. Very odd.

Without Float

My ultimate solution was just to add a div inside the dd that set overflow:hidden to clear the floats.

Solution

Code: css, CSS Jul 25, 2008 ● updated Oct 14, 2008 2 comments

TextMate snippet for clearing floats

update: in the midst of internet connection problems, I managed to double post. Please check out the first post.

Code: css, CSS Jul 14, 2007 ● updated Jul 15, 2007 0 comments

TextMate snippet for clearing floats

I often use positioniseverything.net’s CSS method for clearing floats without structural markup. The code for this technique is not something that I’ve committed to memory yet, so I’m referencing the article all the time (I could just copy it from another project, but it’s just so much quicker to type “css clear float” into google).

Well, positioniseverything.net is about to get several less page hits per week, because I finally threw the code into a TextMate snippet and assigned it the keyword “clearfix”.

${1:.clearfix}:after {
  content: "."; 
  display: block; 
  height: 0; 
  clear: both; 
  visibility: hidden;
}
$1 {display: inline-block;}
/* Hides from IE-mac \*/
* html $1 {height: 1%;}
$1 {display: block;}
/* End hide from IE-mac */
$0

Update: DRYed up based on Jacob’s comment.

Code: css, CSS Jul 14, 2007 ● updated Jul 15, 2007 5 comments

Firefox + Mac + Flash + CSS opacity = peek-a-boo

I came across a fun browser bug this morning that I thought I would share. You can’t have a semi-transparent element cover a Flash animation Firefox on the mac.

I had a popup menu that used CSS opacity to make the menu semi-transparent. It was working fine, but then we threw in a Flash header and the Flash would hide any time you moused over a menu item.

Here are some screenshots that demonstrate the bug. The first is how it looks in Safari, the second demonstrates the bug in Firefox, and the third shows Firefox if I remove the opacity attribute from CSS.

Menu in Safari

Menu in Firefox showing bug

Menu in Firfox

The solution: for now, I’ll just have to live without semi-transparent menus (but they looked so good).

I would venture to guess that this is intentional behavior by Firefox. Since Firefox isn’t a native Cocoa app, it doesn’t have access to all the fancy OS X rendering, so it can’t render transparent elements over elements that it doesn’t have control of (Flash), and it just removes the Flash.

Code: css, CSS Apr 26, 2007 ● updated Apr 26, 2007 12 comments

Collective Idea gets a face lift

After months of good intentions1, we finally launched our new website today.

We were aiming to have a simple site that gives a good idea of who we are and what we do while minimizing the “marketing fluff”. We’re really happy with the result. Check it out and let us know what you think.

Thanks to Brian at ViewChange for his help with the design, and thanks to Matt Slack for his CSS/XHTML wizardry. Check out Daniel’s post for more info about the new site.

  1. A classic case of the mechanic’s car being broken.
Code: css Apr 16, 2007 ● updated Apr 16, 2007 2 comments

CSS Naked Day

What happened to the design?

To learn more about why styles are disabled on this website visit the Annual CSS Naked Day website for more information.

Code: css Apr 05, 2007 1 comment

Subscribe

Browse by Tag