CSS Basic part-3

BOX MODEL, FLOAT and DISPLAY PROPERTY'S

CSS Box Model?

  • All HTML elements can be considered as boxes.
  • box model is used when talking about design and layout.
  • The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content. CSS-Box-Model.webp

Content

  • The content of the box, where text and images appear.

  • the content area's size can be defined with the width, min-width, max-width, height, min-height, and max-height properties.

Padding

  • Clears an area around the content. The padding is transparent.

  • The thickness of the padding is determined by the padding-top, padding-right, padding-bottom, padding-left, and shorthand padding properties.

Border

  • A border that goes around the padding and content.
  • The thickness of the borders are determined by the border-width and shorthand border properties.

Margin

  • Clears an area outside the border. The margin is transparent.
  • The size of the margin area is determined by the margin-top, margin-right, margin-bottom, margin-left, and shorthand margin properties.

Float

  • The CSS float property specifies how an element should float.

    How do you float an image in CSS ?

    img { float: right; }
    

float Property

  • Thefloat property is used for positioning and formatting content e.g. let an image float left or right to the text in a container.

  • left - The element floats to the left of its container

  • right - The element floats to the right of its container

  • none- The element does not float

clear

  • When we use the float property, and we want the next element below (not on right or left), we will have to use the clear property.
  • The clear property specifies what should happen with the element that is next to a floating element.

    clear Property

  • none - The element is not pushed below left or right floated elements. This is default

  • left- The element is pushed below left floated elements

  • right- The element is pushed below right floated elements

  • both- The element is pushed below both left and right floated elements

  • inherit- The element inherits the clear value from its parent
div1 {
  float: left;
}

div2 {
  clear: left;
}

download (1).png

CSS display

  • The display property specifies the display behavior of an element.

display Property

display-property-values.png