Float
To position element is an important step at preparing any layout. Positioning elements in the conventional style i.e through inline-block display have been like any other piece of technology in the world has been time and again been replaced by simpler, easier and lesser hassle prone alternatives, one such being the float ( flex and grid are the most common alternatives)
About Float
- Float property only accepts few values- left, right and none. The left and the right positions the object to the extreme corners of the page.
- Through float even the block-level elements can appear in the same line, inline elements start accepting height and width. Float can change the display properties of an element.
- The float property brings the elements, under its effect, out from the normal flow of the layout. It brings the element to the z-axis above the apparent x and y-axis. It brings the element to come forth, leaving other elements behind it.
- This float property is more commonly used for positioning the media (images), it wraps the text around the floated element.
Clearing Float
When float is applied to a certain element, it does not only effects the selected element but also causes dis-orientation in other elements. In order to maintain harmony among various elements, even after the application of float, there are many methods used to regulate this effect of the float.
- Clearing the float- It is the most straight forward way to deal with the float effects.
.element {
clear: left/right/both ;
}
Though simple in nature, it does carry a major drawback as even after the application of ‘clear’, the parent element does not have a normal flow.
- Containing the float- Another method on this list is to contain the effect of the flow. This is done by simply wrapping the floated text inside a parent element and adding an empty <div> element below the floated element. ( clear is always applied to the upcoming element) . This method is however not semantically correct.
- Over-flow method- It is applied to the parent element. The over-flow accepts only a few values-hidden, auto (default), scroll-x, scroll-y , scroll. This method, however, has to be improvised upon as different browsers react to it differently. This works with ‘Internet Explorer’ only if the height is being fixed, which semantically stands wrong. The ‘overflow-hidden’ property hides the shadows, outlines in an attempt to hide the float effects.
- Clearfix- This is the most popular method in dealing with float effects. It is generally applied to the immediate parent element.
/* Css */
.clearfix: before ,
.clearfix: after {
content=” ”;
display: table/block
}
.clearfix: after {
clear: both ;
}
Pseudo-element is used in ‘ Clearfix’, to create a kind of a wall to restrict the floating elements. They are an inline element.
Get Dnegeyra’s stories in your inbox
Join Medium for free to get updates from this writer.
Until now everything discussed was about design in hard pixel. The web-page is to be made responsive, for which it is important to create flexible containers, columns, media so that the content can adjust to any screen size, through which the webpage is accessed.
.container {
max-width: 1140px;
margin: 0 auto;
}
a ‘ max-width’ is applied, replacing the normal ‘width’ value.







