Author Login | Popular Articles | RSS Feeds | Sitemap

Home | Uncategorized


How To Fix CSS Float Issues

By: Sameep Shah

CSS is great. On somedays I'd go so far as to say it's a lifesaver. But every now and then you'll encounter a CSS issue that will drive you crazy.

In this case we'll talk about two of the more common issues when using the float property to create your layout.

For those of you who're new to CSS, Float is a CSS property that allows you to align your elements, such as DIVs, to create website layouts. The values for Float include Left, Right and None. You can use Floats to align elements and if done properly you can do in such a way that it's dynamic -- almost fluid.

Let's say you need to create an image gallery. Your idea is to place 4 images on each line, but after you place the first image the second image goes to the next line.

I'll admit in the past I used to use negative values to align my images so that the second image would show up next to the first one using the margin-left, right, top, bottom property. I even considered using tables, but opted to use negative values instead. There's nothing wrong with using negative margin property, but not when there's a better solution for it, such as using floats.

If you apply Float to those images then they'll align in one row, then you can continue to add more images using the float property and you wouldn't have to worry about whether they'd line up or not because the float property will recognize that there's too many elements on this line and it will push the images to the next line.

But what if you're using Floats for your website layout, for your divs and not just the images.

There are 2 main issues that you'll face with Floats.

Let's say you have three elements. Parent1(website's main container), Child1(left navigation bar), and Child2(content area). Parent1 is the main div container and your goal is to float the child divs side by side sort of like having a left navigation area and a right content area. Sounds great.

You've set your parent1's height to auto, and you've set child1 and child2's height as auto. But once you open and view it in a webpage the parent element's height is only 1 or 2pixels in height, the child elements seem to look like they're floating above the parent container, and the parent container doesn't seem to recognize the div's height. (see test link 1 on website).

No worries, here is an easy solution for it.

Add overflow:auto; for the CSS of the parent container and it will automatically recognize the floats and will increase in height so that it appears that the floats are part of the parent container just as you wanted. Wow all that in one line.

But don't forget there's still one more Float issue.

The second issue is more of a cross browser compatibility issue with floats, but still as important. If you try to Float for ex: three images to the left and are using margin property, then sometimes the first container that floats will have double the margin in Internet Explorer.

Welcome to the Float Peekaboo Bug / IE Float Doubled Margin Bug.

That's right if you've tried to Float an element and use any kind of margin then you'll notice that it will double the margin in IE.

I'm sure there are some decent hacks, but there's an easy way to fix this in CSS. The Float Margin Killer. In the CSS for that container add display:inline I don't know why but for some reason this property seems to fix the double margin property.

That's it? Yes that's it. Now you can start using floats.

Article Source: http://www.articlesnatch.com

About the Author:
Sam is the founder of Netlyte Houston website Design, A Website Design firm that's geared specifically for building websites for Businesses. Websites that have generated real results such as increase in newsletter sign ups to increase in sales. Plus all of their services are backed by a 100% Guarantee.

| Print | Ezine Ready | |

Recent UnCategorized Articles

  • Start Small When Starting with Affiliate Marketing By: Stacey Reid - When you are starting out new as an affiliate marketer you should be concerned about making a little money at first. Think about making maybe $25 dollars a day. Most newbies make the mistake of thinking to large.
  • How to Stay Focused as an Affiliate Marketer? By: Stacey Reid - Affiliate Marketing is growing at a phenomenal rate in the United States and around the world. The income made in this industry has excelled past the billions of dollars annually. The key to surviving and seeing your share of the profits in this industry is a rock solid plan that you have to stick to.
  • Custom Software Helps With Business Efficiency By: Art Gib - Every small business or large company has its own specific computer challenges and operational demands. Using one-size-fits-all software that comes off the shelf may be enough to suit basic needs, but in order to conduct business at peak efficiency, custom built software will help with highly specialized applications.
  • Learn To Build Your First Website By: April Claeyssens - Learning to build your first website is fun, easy and may be profitable. Once you understand the process, your first website should be live within a couple of days. Your desire to be successful is important. To build your first website you have to be willing to learn and move on with confidence.
  • How am I Protected From Payday Loan Scams? By: Tom Selleck - You might be leery of getting a payday loan based on what little you know about them, or if you or someone you know, has had a bad experience with them. This article comes straight out of Wikipedia to help you understand how the Truth in Lending Act is there to protect you.
  • Online Shipping Status Checks By: scott gallagher - Both for private individuals and large companies, one of the primary concerns that always crops up when they are trying to select a courier company is the ability to track their shipments online.
  • The Key to Retaining the Right Staff By: Karl Hopkins - What is it 'exactly' that motivates people? Prestige?Money? A key to the executive bathroom? Honestly, I doubt weather any of them individually that well or for very long. Yes we all need money.
  • Diet Fitness-Get Fit And Live Better By: Norman Stanley - It seems everybody wants to diet and get fit with millions of dollars being spent every year in the quest for a fitter, leaner more attractive body. Diet fitness is the buzz word of the moment.
  • Use SEO If You Want To Be More Than So, So By: Karl Hopkins - You may have regular customers who return to your website again and again. But most new traffic, and new customers reaching you via the Internet, will be generated from search engine enquiries. Typically potential visitors will type in a key phrase or search term to the likes of Google, Yahoo, or Ask Jeeves.
  • Japanese Bobtail Cat and Kitten Information By: Mitch Endick - The Japanese Bobtail, as the name suggests, has a naturally short tail which can resemble that of a rabbit. The tail is often curved or even kinked. A common color for this breed is tri-color white with red and black, a combination that is considered good luck. Other patterns and colors are accepted.

Search Ebay

Still can't find what you are looking for? Search for it!


Submit Your link to the Open Link Directory Project

Copyright 2005-2008 MJE Sales, LLC. All Rights Reserved.
Proud member of the ArticleCkr Search Network Search Network!
ArticleSnatch.com is free for both publishers and authors to use and is supported entirely from advertising revenue.
Use of our service is protected by our Privacy Policy and Terms of Service.