Css Course


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:
selector { float: value; }
- Example (Two <div> tags, first with float:right, the second with float:left, and a text content after them).
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).
<style>
#dv1 {
width: 200px;
float: right;
border: 2px solid green;
}
#dv2 {
width: 200px;
float: left;
border: 2px solid blue;
}
</style>

<h4>Example float</h4>
<div id='dv1'>DIV 1, with float: right;</div>
<div id='dv2'>DIV 2, with float: left;</div>
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:
selector { clear: value; }
- 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):
<style>
#dv1 {
width: 200px;
float: right;
border: 2px solid green;
}
#dv2 {
clear: right;
width: 200px;
float: left;
border: 2px solid blue;
}
</style>

<h4>Example CSS clear</h4>
<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.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag defines the clickable areas inside the image map?
<map> <img> <area>
<img src="image.jpg" usemap="#map1">
<map name="map1">
  <area shape="rect" coords="9, 120, 56, 149" href="#">
  <area shape="rect" coords="100, 200, 156, 249" href="#">
</map>
Which CSS property defines what is done if the content in a box is too big for its defined space?
display overflow position
#id {
  overflow: auto;
}
Click on the event which is triggered when the mouse is positioned over an object.
onclick onmouseover onmouseout
document.getElementById("id").onmouseover = function(){
  document.write("Have Good Life");
}
Indicate the PHP variable that contains data added in URL address after the "?" character.
$_SESSION $_GET $_POST
if(isset($_GET["id"])) {
  echo $_GET["id"];
}
CSS Float and Clear

Last accessed pages

  1. Get and change IFrame content through a JavaScript script created in another IFrame (16340)
  2. setTimeout and this with bind() method in JavaScript class (4924)
  3. Star shapes with CSS (11114)
  4. Follow the mouse cursor with a DIV inside a Parent (8273)
  5. CSS Course - Free lessons (21648)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (318)
  2. PHP Unzipper - Extract Zip, Rar Archives (110)
  3. Read Excel file data in PHP - PhpExcelReader (101)
  4. SHA1 Encrypt data in JavaScript (81)
  5. Get and Modify content of an Iframe (74)
Chat
Chat or leave a message for the other users
Full screenInchide