CSS Tutorials – Part1

Guys,

We will see some general css tutorial concepts..

How to display a column wise table with div?? Say Column1  Column2 Column 3 should display like a table inline..

We can achieve this by using

#col1,#col2,#col3,#col4{
    #display: block;
    #display: inline-box-align;
    display: table-cell;
    margin: auto;
} 

(or)
 
.column {
  display: table-cell;
}

for the below html code

                    <div id="col1" class="column">Column1</div>
                    <div id="col2" class="column">Column2</div>
                    <div id="col3" class="column">Column3</div>
                    <div id="col4" class="column">Column4</div>

Margin

The margin clears an area around an element (outside the border). The margin does not have a background color, and is completely transparent.

The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used, to change all margins at once.

The margin property can have from one to four values.

  • margin:25px 50px 75px 100px;
    • top margin is 25px
    • right margin is 50px
    • bottom margin is 75px
    • left margin is 100px
  • margin:25px 50px 75px;
    • top margin is 25px
    • right and left margins are 50px
    • bottom margin is 75px
  • margin:25px 50px;
    • top and bottom margins are 25px
    • right and left margins are 50px
  • margin:25px;
    • all four margins are 25px

Padding

The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.

The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once.

padding-top:25px;
padding-bottom:25px;
padding-right:50px;
padding-left:50px;

The padding property can have from one to four values.

  • padding:25px 50px 75px 100px;
    • top padding is 25px
    • right padding is 50px
    • bottom padding is 75px
    • left padding is 100px
  • padding:25px 50px 75px;
    • top padding is 25px
    • right and left paddings are 50px
    • bottom padding is 75px
  • padding:25px 50px;
    • top and bottom paddings are 25px
    • right and left paddings are 50px
  • padding:25px;
    • all four paddings are 25px

Difference Between Margins and Padding?

What Are Margins?

Margins in CSS make up the vertical and horizontal areas between elements. If elements have no margins around them, they will bump right up against each other. Some elements have margins by default, so often even if you haven’t added a margin, you may still see one.

Here’s a visual demonstration of CSS margins:margins-css

Margins can be set using the margin property (which is shorthand, representing the four margin values for an element) or by the longhand margin-topmargin-right,margin-bottom, and margin-left properties. The order in shorthand is: top, right, bottom, left.

What is Padding?

So what about padding? Well, the padding of an element is the horizontal and vertical space that’s set around the content area of the targeted element. So padding is on the inside of a box, not the outside.

Here’s a visual demonstration of CSS padding:padding-css

Similar to margins, padding is set using the shorthand padding property, and can also be done using longhand: padding-toppadding-rightpadding-bottom, andpadding-left.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s