The CSS margin properties are used to generate space around elements. the margin property size of white space of the border.with CSS you have full control over the margin.There are the css property for setting the margin of each side of an element.



Margin - Individual Sides:-

CSS has the property for specifying the margin for each side of an element.
  1. margin_top
  2. margin-left
  3. margin-right
  4. margin-bottom
All the margin properties can have the following values:-

  1. auto - the browser calculates the margin
  2. length - specifies a margin in px, pt, cm, etc.
  3. % - specifies a margin in % .
  4. inherit - specifies that the margin should be inherited from the parent element
Note: Negative values are allowed.

The following example sets margins for all sides of a <p> element:-

{
    margin-top: 100px;
    margin-bottom: 100px;
    margin-right: 150px;
    margin-left: 80px;
}



Shorthand Property:-

You can write margin property in one line to short the code, You can write the margin property for the following individual property.

margin-top , margin-right, margin-bottom, margin-left


Example:-

{
    margin: 100px 150px 100px 80px;
}



Auto Value:-

The auto property is used to horizontally center the element within its container.
The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.

div {
    width: 300px;
    margin: auto;
    border: 1px solid red;
}

inherit Value:-

This example lets the left margin be inherited from the parent element.

div.Header {
    border: 1px solid red;
    margin-left: 100px;
}

p.first {
    margin-left: inherit;
}


Margin Collapse:-

Top and bottom margins of elements are sometimes collapsed into a single margin that is equal to the largest of the two margins.This does not happen on left and right margins? Only top and bottom margins?

Look at the following example:-

h1 {
    margin: 0 0 50px 0;
}

h2 {
    margin: 20px 0 0 0;
}

All CSS Margin Properties:-


PropertyDescription
marginA shorthand property for setting the margin properties in one declaration
margin-bottomSets the bottom margin of an element
margin-leftSets the left margin of an element
margin-rightSets the right margin of an element
margin-topSets the top margin of an element

IF you have any question about this lecture you can comment blow. feel free to contact me.
you can also Visit my YouTube channel by clicking on this Link YouTube Channel.

0 comments:

Post a Comment

Thanks

 
Blogger Templates1 school © 2013. All Rights Reserved. Powered by Blogger
Top