HTML CSS examples for CSS Property:float
The float CSS property sets whether a box should float to the left, right, or not at all.
The following table summarizes the float Property.
Item | Value |
---|---|
Default value: | none |
Applies to: | All elements |
Inherited: | No |
Animatable: | No. |
The syntax of the property is as follows:
float: left | right | none | initial | inherit
The following table describes the values of this property.
Value | Description |
---|---|
left | float on the left side of its containing block. |
right | float to the right. |
none | The box is not floated. This is default value. |
initial | Sets this property to its default value. |
inherit | take the value of its parent element float property. |
The example below shows the float property.
<!DOCTYPE html> <html lang="en"> <head> <title>Example of CSS float property</title> <style type="text/css"> p {<!--from w w w . j av a 2 s .c o m--> width: 150px; padding: 50px 0; text-align: center; } p.red { float: left; background: #ff0000; } p.green { float: right; background: #00ff00; } </style> </head> <body> <p class="red">Float Left</p> <p class="green">Float Right</p> </body> </html>