Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to limit the scope CSS float and clear?

Tags:

css

css-float

Example of the problem at: http://jsfiddle.net/xZmFg/4/

Surely there is a way to get the description to immediately follow the inputs (below, not to the right) and not end up below the menu...

I realise that with 'float' you are breaking out of the flow of the content, but isn't there a way to only apply to the space inside of the parent container?

like image 737
HorusKol Avatar asked Apr 20 '11 03:04

HorusKol


People also ask

How do you clear a float in CSS?

To clear a float, add the clear property to the element that needs to clear the float. This is usually the element after the floated element. The clear property can take the values of left , right , and both . Usually you'll want to use both.

What are two valid techniques used to clear float CSS?

Adding a clear element after the floating element(s) is the most common way people use to clear floats in CSS and you might be implementing this thing in your markup already. In this technique, we basically use a clear element to clear floats of the siblings.

Which CSS property is used to prevent elements from floating?

Note: Elements next to a floating element will flow around it. To avoid this, use the clear property or the clearfix hack (see example at the bottom of this page).

Is it good practice to use float in CSS?

The short answer: clear: both. Floats work really well in small cases like when there's an element, such as a button, that you'd like to move to the right of a paragraph. But the real issue arises when you start using floats to lay out entire web pages. And the reason for that is: floats are not meant for layouts!


2 Answers

You can have your description's and form inputs' parent element contain all their floats using overflow: hidden:

.content-box {
    overflow: hidden;
}

This way, they won't interfere with the floats on the sidebar elements.

jsFiddle preview

like image 154
BoltClock Avatar answered Sep 26 '22 02:09

BoltClock


You can float the container around the inputs and your paragraph:

.content {
    float: left;
}

And then drop the clear: left; on .description as it doesn't do anything (or leave it in).

http://jsfiddle.net/ambiguous/QdY44/

like image 41
mu is too short Avatar answered Sep 25 '22 02:09

mu is too short