Float

CSS allows you to "wrap" an element around other. You can do this with the float property.
This property shifts an item horizontally, left or right from its original placement, leaving a blank space in the opposite direction, which will be filled by the next HTML element. But the elements before the floating element will not be affected.
A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing parent.
If you place several floating elements after each other, they will float next to each other if there is room.
  - Values:   - Syntax:   - Example (Two <div> tags, first with float:right, the second with float:left, and a text content after them.):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>float</title>
 <style type="text/css"><!--
 #dv1 {
  width: 200px;
  float: right;
  border: 2px solid green;
 }
 #dv2 {
  width: 200px;
  float: left;
  border: 2px solid blue;
 }
 --></style>
</head>
<body>
 <div id="dv1">DIV 1, with float: right;</div>
 <div id="dv2">DIV 2, with float: left;</div>
 Text content after the floated DIVs.
</body>
</html>
The first DIV is pushed to the right, leaving a blank space to its left. The second div is pushed to the left in that space, leaving another empty space in its right side, that will be filled by the next item, if fits (here a text content).
  - Result:
DIV 1, with float: right;
DIV 2, with float: left;
Text content after the floated DIVs.

- Absolutely positioned elements ignores the float property.

Clear

The clear property has an action similar to <br> HTML tag that moves to a new row the next element.
When an element is floated it leaves an empty space in the oposite direction. With the "clear" property can be avoided the filling of that blank space by the next item.
The clear property is used to insert a break when encountering a new section of the layout to stop the wrapping effect. It specifies which sides of an element other floating elements are not allowed.
  - Values:   - Syntax:   - Example (A new version of the example above, here is added the clear:right in the "#dv2" selector and a <br /> tag with clear:both before the text content):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 <title>clear</title>
 <style type="text/css"><!--
 #dv1 {
  width: 200px;
  float: right;
  border: 2px solid green;
 }
 #dv2 {
  clear: right;
  width: 200px;
  float: left;
  border: 2px solid blue;
 }
 --></style>
</head>
<body>
 <div id="dv1">DIV 1, with float: right;</div>
 <div id="dv2">DIV 2, with float: left;</div>
 <br style="clear:both" />
 Text content after the floated DIVs.
</body>
</html>
As you can see, the clear property stops the wrapping effect.
  - Result:
DIV 1, with float: right;
DIV 2, with float: left;

Text content after the floated DIVs.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
What attribute makes the input text box to not be modified by the user?
checked="checked" readonly="readonly" disabled="disabled"
<input type="text" value="fixed-value" readonly="readonly" name="a_name" />
What CSS property allows you to create rounded corners in your webpage design?
background-size border-size border-radius
.class {
  border:2px solid blue;
  border-radius:1.2em;
}
What instruction displays a confirmation dialog box to the viewer, who must then click OK or Cancel to proceed?
indexOf() confirm() prompt()
var ques = window.confirm("The result of 0+0 is 0?");
if (ques) alert("Corect");
else alert("Incorrect");
Indicate the PHP function that returns the lowest number of the parameter values.
floor() ceil() min()
$min_nr = min(12, 8, 25, 13);
echo $min_nr;        // 8
CSS Float and Clear

Last accessed pages

  1. Working with getElementById (1718)
  2. Voting Poll System script PHP-AJAX (664)
  3. jQuery ajax() method (2078)
  4. Countdown Timer with starting time added into a form (527)
  5. PHP MySQL - using MySQLi (1075)

Top accessed pages

  1. PHP-MySQL free course, online tutorials PHP MySQL code (5613)
  2. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (5422)
  3. Get Attribute (ID, Class, Name, Title, Src) with jQuery (5222)
  4. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (4976)
  5. PHP Chat Script (4759)