Showing posts with label #CSSMargin. Show all posts
Showing posts with label #CSSMargin. Show all posts

Chapter 5 - What are Margins in CSS?

What are margins in CSS and how to set a margin with css coding?

Do you really want to learn CSS?
Learn CSS is easy if you know the right path of the information provider about style sheet tutorial.

But with the technological evolution or breakthrough in blogging, it is not possible for everyone to search the absolute information on the net.

However +Google is continuously making lots of efforts to provide the best search result but the the search result is not as per the requirement of the searcher yet.

It will take a time to produce the 100% relevant search result about the topic.

So, we decided to create a blog with the in-depth information about learning CSS or style sheet.

Today's topic is CSS Margins.

CSS Margins are outer space between the two or more. In other words, a css margin it the space all around an element.

Margins are of 4 sides/types and it is a Clock wise direction in coding:-
  1. Margin-Top
  2. Margin-Right
  3. Margin-Bottom
  4. Margin-Left
By default are side has margin existed but with your CSS coding you can either remove or extend margin of 4 the sides.

The margin property can be set for the top, left, right and bottom of an element. (See below example)


 Syntax of 4 sided margin:-

 margin-top:Value;
 margin-right:Value;
 margin-bottom:Value;
 margin-left:Value;

/*NOTE:- A margin value could be in Pixel, Percentage or auto etc.*/ 

You can also declare a margin value in a single row as it is shown in below example:-

 For setting all 4 sided margin use TRBL  format. Example:-

 margin:T R B L; (Top, Right, Bottom, Left)
 margin: 10px 20px 30px 40px;


/*NOTE:- A margin value should read clock wise.*/ 

 If values of all sided margin is same then use the following syntax:-

 margin:10px; /*4 sides margin*/
 margin:-10px; /*negative margin of 4 sides*/
 margin:10px 20px; /*top, right margin*/
 margin:10px 20px 30px; /*top,right, bottom*/

/*This will set 10px margin for all 4 sides*/
/*You can also set a negative margin value*/
/*You can also set margin of two sides*/
/*You can also set margin of three sides*/

You can read 4 sided margin as TRBL (This term is first ever used by CSSBasicTips).

Chapter 7 - What is Division in CSS?

The word "Division" derived from the word "Parts". This means that you can make as many parts as you want to show different elements on your website with the help of style sheet.

You can use almost every bit of your website page's space.

In my previous chapters, you have learnt about the syntax or properties of css.

Now it is time to learn about how to use in HTML coding. It starts with DIV tag in HTML and you can reserve space of a website page with as many DIV tag as you want with the help of style sheet.


To create above layout; use the coding as shown below:-


Example of CSS CODING


 /* Here I am using for CSS IDs to create Main Screen, Left, Center and Right Division*/

 #main
 {
    width:425px;
    height:261px;
    background-color:blue;

    border:20px solid brown;
 }
 #left
 {
    height:116px;
    width:130px;
    background-color:#FFFFFF;
    border:2px solid red;
    border-radius:20px 20px 0px 0px;  
    float:left;
    border-bottom:50px solid red;
 }
 #right
 {
    height:116px;
    width:130px;
    background-color:#FFFFFF;
    border:2px solid green;
    border-radius:20px 20px 0px 0px;  
    float:right;
    border-bottom:50px solid green;
 }
 #center
 {
    height:116px;
    width:130px;
    background-color:#FFFFFF;
    border:2px solid pink;
    border-radius:20px 20px 0px 0px;
    margin-left:10px;  
    float:left;
    border-bottom:50px solid pink;
 }

Now have a look on the HTML coding to make divisions.

Example of CSS CODING


 /* Here I am using DIV Tag of HTML to make Divisions on the page*/

 <div id="main">
   <div id="left"></div>
   <div id="center"></div>
   <div id="right"></div>
 </div>

Now I hope everything is clear to you with respect to Division in CSS.

For more examples on CSS based layout and the use of all CSS attributes and properties; see blog posts.

And share your feed back.