Saying Goodbye to the overflow: hidden Clearing Hack

https://i0.wp.com/1.bp.blogspot.com/_BGE4sL0uhQA/TVKJbZMrKrI/AAAAAAAAAB8/De5yG6iAI6s/s1600/css.png

I’ve been thinking of this for a while now, and it’s finally time to part ways with the overflow: hidden (and overflow: auto) clearing hack. Jeff Starr’s recent and excellent post – The New Clearfix Method – and the ensuing comments were enough to finally prompt me to write about it here. (And since I started writing this, Jonathan Snook has started a Twitter dialog about overflow vs. clearfix).

While the clearfix method is a tried and true hack, I’ve always disliked muddying up my HTML markup with crufty “clearfix” classes strewn about. So I ended up using overflow: hidden as much as I could. But overflow: hidden is not without its drawbacks. Although there is no extra class to apply in the HTML (win!), there may be situations when you want to have child elements positioned partially (or entirely) outside of their overflow: hidden wielding parent (or other ancestor) container. In these cases, the container with overflow: hidden will clip the element that you’re trying to partially (or entirely) position outside of it. (Case in point: If you use suckerfish dropdowns, try setting overflow: hidden on the outermost list).

So although overflow: hidden is not usable in all situations, I used to prefer it over using the “clearfix” class method. But in reality I ended up with both: I had overflow: hidden where I could get away with it, and “clearfix” classes where I couldn’t use overflow: hidden. It bothered me a bit to mix and match two different clearing methods, but I was happy to have fewer “clearfix” classes violating my otherwise semantic markup Kumbaya festival.

Then in his presentation at An Event Apart 2008 in San Francisco, Dan Cederholm suggest using the class name “group” rather than “clearfix” – a suggestion which later made it into his book Handcrafted CSS. It’s a minor thing, but I do like the improved semantics (in most cases) of the “group” class name over the “clearfix” class name, so I adopted this approach and felt okay about using it as a fallback when overflow: hidden wasn’t feasible.

In his talk and in his book, Cederholm also walks through the “big long list” idea of applying the rules for the clearfix (renamed to “group”) class directly to the selectors that need them in the CSS.

Big Long List

This keeps the HTML more pure while avoiding the drawbacks of overflow – a total win-win. But it does mean extra bloat in the CSS. Probably okay for smaller sites, but it can quickly get unruly with larger sites. I tried this approach on a few projects and decided the CSS bloat was indeed too much, so I stuck with the mix of overflow: hidden and the “group” class.

The Catalyst

But I’m now saying goodbye to overflow: hidden and the deciding factor for me is CSS3. Specifically box-shadow. At least in the sense that box-shadow was the first property I noticed being negatively impacted by the use of overflow: hidden. Like the positioned child elements mentioned above, box-shadow can get clipped when the parent (or other ancestor) element has overflow applied.

And there are several other things to consider as we move forward using more CSS3. Text-shadow and transform can also potentially be clipped by overflow: hidden (see the demo).

Example of overflow:hidden clipping a box-shadow

As we rely more and more on CSS3 properties we can rely less and less on overflow as a clearing method. So I’ll be abandoning overflow and relying upon clearfix (Jeff Starr edition) via a mix of the “.group” class in the markup and the “big long list” approach.

Suggested Reading

Quoted from: http://fordinteractive.com/2009/12/goodbye-overflow-clearing-hack/

Web Programming: Curved boxes in CSS

Updates!!!

..Now IE ?? .. As IE is not a good browser to work with css, we need to make it so. Here, you need to use a nice css hack

Curved boxes are straight forward to do in CSS. Here’s a quick tutorial of how to achieve curved boxes in CSS and what’s to come in CSS 3…

The CSS:

  1. .curved {
  2. -moz-border-radius:10px;
  3. -webkit-border-radius:10px;
  4. behavior:url(border-radius.htc);
  5. }

The HTML:

<div>Curvd div</div>

The explanation :

Do you really want an explanation for this simple 3 line css ?. I don’t think so. Ofcourse if you need, I can.

Browsers :

All browsers :)

Download

Quoted from: htmlremix.com

What we want to achieve

Here’s a graphic of the final product – a box with curved edges that will expand if the text is enlarged.

Curved box in CSS

To start with we will make the graphics in Photoshop.

Curved boxes – Making the graphics

Open Photoshop and choose the rounded rectangle tool (shortcut of U on the keyboard). Decide on the size and colour of your rectangle and then draw a rectangle. You can make the curve bigger or smaller by changing the size of the radius.

Cut the curve out just below the last pixel of the curve. You can make the bottom curve quickly and easily by going to Image > Rotate Canvas > 180 º CW

Cutting the curve in  Photoshop

The markup

In order to create a cross-browser friendly box we need to attach the image to HTML elements. This method requires at least two elements inside the div. In this case we use the h2 and p tags and apply a background image to each through the CSS.

Our markup looks like this

<div class="curved-box">
  <h2>This is a curved box</h2>
  <p>This text will resize and not break the box.</p>
</div>

Applying the CSS

We add the curves through the CSS by accessing the elements and applying a background image. The top one is applied to the h2 and the bottom to the p tag. Make sure the background to the div is the same colour too.

.curved-box
    {
    width: 298px;
    margin: 10px;
    background-color: #c3d0d4;
}

.curved-box h2
    {
    background: #c3d0d4 url(../images/curve_top.png) no-repeat left top;
    color: #f4fbfd;
    padding: 10px 15px 5px 15px;
}

.curved-box p
    {
    background: #c3d0d4 url(../images/curve_bottom.png) no-repeat left bottom;
    margin: 0px;
    padding: 5px 15px 10px 15px;
    text-align: left;
}

Using this code the text will resize without breaking the box.

Have a look at the code in action in the example.

Browser support: IE5+, Netscape 6+, Firefox 1+, Safari 1+, Opera 7+, Flock, Camino

CSS3 will make it even easier

Once CSS3 is finally agreed it will be even easier to curve the edges of boxes. “Border-radius” will curve the corner of the box. For now browser support is not great and indeed browsers have their own proprietary properties:

-webkit-border-radius: 10px; /* Safari prototype */
-moz-border-radius: 10px; /* Gecko browsers */
border-radius: 10px; /* Everything else - limited support at the moment */

Currently supported in Camino 1+, Firefox 1+, NOT IE. The code degrades gracefully so if it is not supported there will be no curves but it will still render. Check out the example to see it in action.

source: http://shapeshed.com