Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

Float

The CSS float property specifies how an element should float.

The CSS clear property specifies what elements can float beside the cleared element and on which side.

IMG_3508

The float Property

The float property is utilized to position and format content, such as allowing an image to be aligned to the left of text within a container.

The float property can be assigned one of the following values:

  • left – The element is floated to the left of its container.
  • right – The element is floated to the right of its container.
  • none – The element does not float and is displayed where it naturally occurs in the text. This is the default behavior.
  • inherit – The element inherits the float value of its parent.

At its simplest, the float property allows text to wrap around images.

Example – float: right;

In the following example, an image is set to float to the right within a text.

IMG_3513

Example

img {
  float: right;
}

 

Example – float: left;

The subsequent example indicates that an image is set to float to the left within a text.

IMG_3510

Example

img {
  float: left;
}

Example – No float

In the example below, the image will be displayed inline with the text, without any floating effect (float: none;):

IMG_3512

 

Example

img {
  float: none;
}

Example – Float Next To Each Other

By default, div elements are displayed stacked vertically. However, applying float: left allows the elements to align horizontally beside each other.

Example

div {
  float: left;
  padding: 15px;
}

.div1 {
  background: red;
}

.div2 {
  background: yellow;
}

.div3 {
  background: green;
}