What's so difficult about floating?

liunx

Guest
I've done a few the tutorial at w3schools.com on CSS.
I didn't learn anything new.
I thought I had mastered everything to know about CSS and was scratching my head wondering what all the fuss was about.

But then I found a few long long essays (well... several web pages) dedicated to floating and having three columns etc.

Em... am I missing something?
Why is it so hard to grasp?
And why are there 'bugs' that need to be overcome using 'hacks'?

Erm... I don't like the word hack... that says illegal, naughty, shouldn't do. ;)

Are there any other complex issues that I need to be worried about?

Any feedback to any of the above said would be really appreciated.


Thanks.


JamWell, let's look at a few things. How should you position your block-level elements? Absolute positioning solves it in pixel size so that it works great on any screen, but when the browser is resized, it can get extremely messy. The way to avoid all kinds of related problems with absolute positioning is to use floats. A float just takes a block-level element, takes it out of the document flow (hence the term), and positions it to the right or left. The clear property allows for elements to be placed back into document flow. It's kind of like reversed gravity.

By the way, "hackers" are good people -- crackers are the bad people. Hack is just a widely-misunderstood term.Originally posted by jammer20002


I thought I had mastered everything to know about CSS and was scratching my head wondering what all the fuss was about.



Now there's a dangerous thing to say, especially give the rest of your post. One way to spot someone who isn't an expert is to listen to them tell you they have "mastered everything" to do with a subject.Originally posted by dr john
Now there's a dangerous thing to say, especially give the rest of your post. One way to spot someone who isn't an expert is to listen to them tell you they have "mastered everything" to do with a subject.

yes i totally agree. :)
i wasn't meaning to sound like that!Personally I find that there's nothing particularly hard about floating things, I use it all the time.

Floating things is great for if you want to create several column layouts and navigation bars (where each link is a fixed size), there are other uses, maybe I'll remember them later. :D

Of course, don't count out absolute positioning, I use that on my current site for the side navigation bar, I could have used floats but that would have required more effort.

There is a danger with floats though, because they are taken out of the flow of the document they are allowed to "break out" of the edges of the parent element, this causes particular problems when floated elements run longer than the parent element and so, for want of a better phrase, they stick out the bottom.Yeah, both absolute positioning and floats have their ups and downs. I personally like floats more. The problems lavalamp mentioned can be overcome with the afforementioned clear property and also by adding width to the parent elements, and if necessary margins. In fact, in order for absolutely positioned elements to stay in the document flow, I often use margins instead of the top, right, bottom, and left properties. But again, it's kind of just preference. ;)Originally posted by Jona
I often use margins instead of the top, right, bottom, and left properties.Yeah, I find that margins are usually invalueable, much better than using relative positioning (although, relative positioning is still useful under certain circumstances).Floats are a nifty tool for creating multi-column layouts, but I’ve considered not using them as much, and I have not in one of my latest piles of junk. Take a gander at Floats don’t suck if you use them right (<!-- m --><a class="postlink" href="http://www.meyerweb.com/eric/thoughts/2004/07/17/floats-dont-suck-if-you-use-them-right/">http://www.meyerweb.com/eric/thoughts/2 ... hem-right/</a><!-- m -->), by Eric Meyer. (Note, I haven’t stopped floating things [it’s so much fun], but I’ve put more thought into using alternate methods of positioning, such as absolute positioning [which isn’t evil at all].)
 
Back
Top