Simple Clearing of Floats

by Hazem 17. November 2009 22:18

 

by Alex Walker

Without wanting to stray too deeply in Simon and Stuart’s technical CSS territory, I thought this was worth noting.

For all it’s many advantages, sometimes it’s the little things that CSS layout makes difficult that really get to you. Clearing floated elements is a good example.

The Problem:

One of the simplest and most common layout structures involves the placing of a small, set-width DIV — perhaps navigation, a quote or a bio — within a larger wrapping DIV that contains the remaining content. In a markup this might be something like:

 
<div id="outer">
<div id="inner"> <h2>A Column</h2> </div>
<h1>Main Content</h1>
<p>Lorem ipsum</p>
</div>
 
	<div id="outer">
	<div id="inner"> <h2>A Column</h2> </div>
	<h1>Main Content</h1>
	<p>Lorem ipsum</p>
	</div>
	

We can set the width of ‘#inner’ (let’s say ‘width:20%’), but, being a block level element, the main content will always wrap beneath, unless we float it (either left or right). Here our classic problem begins.

If ‘#inner’ is shorter than #outer, all is well.

However, if ‘#inner’ grows taller than it’s wrapping parent, it breaks through the bottom edge of ‘#outer’. It’s as if ‘#outer’ forgets it’s supposed to be keeping tabs on what ‘#inner’ is doing as soon as you float it.

As we can’t always control the amount of content in these DIVs, it certainly presents a problem. Here’s a typical example of the problem in action. (Thanks to Pixy for the neat little content-gen script).

The Solutions:

a) The Markup Method: The first and W3C-recommended approach is a little ugly – extra markup. At the very end of your content, toss in a cleared element – typically something like <br style="clear:both"/>. It’s the HTML equivalent of wedging matchsticks into your window frame to jam a window open. This works, but ‘dirties your page’ with stuff that only exist so it renders properly.

b) The Aslett/PIE Method: Less than 12 months ago Tony Aslett working with PositionIsEverything.com came out with a new method so diabolically clever that they had to have been sitting in a fake island volcano, stroking a large white cat and laughing fiendishly when they thought of it.

You’ll need to read the tutorial to get the full story, but, in short, they use a little-known, rarely-used pseudo class (:after) to place a hidden, cleared full-stop after the content. Combined with a sprinkling of hacks, this works beautifully – but gives me a headache over my left eye when I think about it.

c) The Ordered List Method: Last October Steve Smith from Orderlist.com published a slightly simpler method. Again, read his tutorial to get the low-down, but in short, his method involves ‘Floating nearly Everything’ (FnE), which naturally enough includes the outer DIV. This can have a considerable effect on the way your design stacks and as Steve says ‘it takes a little more tweaking’ but in general this method seems a little more robust to me.

d) That was my ‘current state of play’ until last week when SitePoint Forum’s own CSS Guru, Paul O’Brien, nonchalantly pointed out that adding a ‘overflow:auto’ to the outer DIV did the trick.

‘Rubbish’ I thought to myself.

Half an hour of testing later, I was amazed to find Paul was 100% correct – as this example shows. It seems that reminding the outer DIV that it’s overflow is set to ‘auto’, forces it to think “oh yeah.. I’m wrapping that thing, aren’t I?”.

This fact is so boringly simple that it’s hard to know if thousands of developers are well aware of it, but never thought to mention it. I know I showed the example page to four CSS-savvy SitePoint colleagues and all shock their heads, blinked slowly and said “Whaa…?” (or something similar).

From my testing, it seems to work identically in virtually every browser. Even IE4 seems to love it – only NS4 freaks out, and I’m not totally convinced a few hacks couldn’t get that working.

We haven’t had time yet to thoroughly test this method under rigorous match conditions, but so far there don’t seem to be any major drawbacks.

Certain combinations of margin and padding can force internal scrollbars. If you can’t ‘massage’ them away, we found ‘overflow:hidden’ has virtually the same effect without the scrollbars. The only drawback of ‘hidden’ seems to be the cropping of some images if they’re placed lower in the page.

Both issues seem very manageable.

Nice work, Paul.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

40+ Best Photoshop Tutorials for Creating Buttons and Badges | Naldz Graphics

by Hazem 13. November 2009 18:14

Tags: ,

20+ Free Graphic Resources Sites for Your Library | GraphicMania.net

by Hazem 13. November 2009 17:44

Tags:

Firefox 3.6 Beta Adds Aero Peak Support to its Browser

by Hazem 9. November 2009 16:13

image With the release of Windows 7 and its anticipated feature “Aero Peak” I leaving IE8 back to FF (finally). The feature although not very important as much as a security fix allows a better productivity for those, like myself, who have dozen of open tabs waiting to be read.

image

While I lost many of my add-on support, for now, with the new release I am finding it an excellent addition to Firefox original features. Moreover, FF 3.6 beta has a lower memory footprint (usage) than version 3.5 as well as Chrome 4.x and Safari.

Mozilla has also added a feature (more like an extension to its Themes option) which allows changing the look of the browser window(window color/background image, tabs font & visual style).

  
image

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

Horizontal Sub-nav with CSS & jQuery - Subnavigation Tutorial - CSS Tutorial - jQuery Tutorial

by Hazem 8. November 2009 10:30

An easy way to create a navigation menu with submenu using CSS and jQuery.

subnav-menu-with-css

Horizontal Sub-nav with CSS & jQuery - Subnavigation Tutorial - CSS Tutorial - jQuery Tutorial

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

Tips to Write Better CSS Code

by Hazem 6. November 2009 22:02

 

1. Don’t Use Global Reset

2. Do not use IE Hacks

more at http://webdeveloperplus.com/css/tips-to-write-better-css-code/

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: ,

30+ Fresh & Amazing jQuery Plugins & Tutorials

by Hazem 5. November 2009 02:17

Tutorials

1. How to add preloader with loading image in a gallery using jQuery


Use a jQuery preloader while images are loading in the gallery.
» View Demo | » View Tutorial

read the next 10 tutorials on WebDeveloperPlus

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

101 LINQ Samples - Visual C# Developer Center

by Hazem 5. November 2009 01:23
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

HowTo: Recover WordPress Password

by Hazem 4. November 2009 22:19

Through a MySQL command line
(replace all details in bold with your own data)

1. Type “mysql -u root -p” (Logs in to MySQL)
2. Enter your password at the prompt.
3. Type “use name-of-database” (Select your WordPress database)
4. Type “show tables LIKE ‘%users’;” (Finds the WordPress user table)
5. Type “SELECT ID, user_login, user_pass FROM name-of-table WHERE user_login = ‘username‘;” (Observe the encrypted password)
6. Type “UPDATE name-of-table SET user_pass=MD5(’new-password‘) WHERE user_login = ‘username‘;” (Updates the database with the encrypted password)
7. Type “SELECT ID, user_login, user_pass FROM name-of-table WHERE user_login = ‘username‘;” (To confirm password was changed)
8. Type “exit” (Exits the MySQL client)
9. Login to WordPress and using your username and new password.

If you don’t have this type of access or if this is too difficult for you, you can ask your web host to do it for you and once you have your new password, login and change the password to something you know and can remember.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

15 Essential Checks Before Launching Your Website

by Hazem 4. November 2009 15:23

By Lee Munroe  (http://www.smashingmagazine.com/)

April 7th, 2009

Your website is designed, the CMS works, content has been added and the client is happy. It’s time to take the website live. Or is it? When launching a website, you can often forget a number of things in your eagerness to make it live, so it’s useful to have a checklist to look through as you make your final touches and before you announce your website to the world.

This article reviews some important and necessary checks that web-sites should be checked against before the official launch — little details are often forgotten or ignored, but – if done in time – may sum up to an overall greater user experience and avoid unnecessary costs after the official site release.

http://www.smashingmagazine.com/2009/04/07/15-essential-checks-before-launching-your-website/

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: ,

About the author

Something about the author