The CSS Float Property
As an example of column floating, have a look at the image below, taken from a browser:
Notice two things about the CSS code, though. The first thing to notice is that we have used float: left. The second thing to notice is that we have set a width for the column of 200 pixels. If you don't set a width then any text you have for your column will simply flow from left to right.
There is a problem with our approach, however. Have a look at the columns in the browser again. Although they look nicely side-by-side, this is only because we manipulated the browser. We deliberately made it smaller so that the text resized itself. If we make the browser bigger, here's what happens:
To stop it doing that, you can add the class to the second DIV, as well:
To start text on a new line underneath the columns, you can use the clear property in CSS, remember:
Friday, 10 July 2015
The CSS Float Property
.clear {
clear: left;
}
This clears the float value and returns you to the normal, static flow. (You can replace left with right or both depending on your needs.)
0 comments:
Post a Comment