HOME | PHP Tutorial | CSS
facebook icon
HTML Tutorial

CSS Tutorial

CSS Margin, top, bottom, left, right

The margin attribute sets "as the name says" a distance beyond the previously set boundary. The defined edge will not have any color, in other words it will be transparent. The CSS margin properties are used to create space around boundary, outside of any defined borders.

Margin - Individual Sides as top, right, bottom, left

With CSS, you have full control over the margins and you can add any value. There are properties for setting the margin for each side of an element (margin-top, margin-right, margin-bottom, and margin-left).

All the margin properties can have the next value:
  • length - specifies a margin in px, pt, cm, etc. for top, bottom, left, right,
  • % - specifies a margin in % of the width of the containing element for top, bottom, left, right,
  • inherit - specifies that the CSS margin should be inherited from the parent element,
Note: Negative value for margin are not allowed for CSS margin-top, margin-right, margin-bottom, margin-left

If the margin property has this four value:
margin: 12px 15px 12px 16px;
top margin is 12px
right margin is 15px
bottom margin is 12px
left margin is 16px

div-box1 { margin: 12px 15px 12px 16px; }

CSS margin - Shorthand Property

To shorten the code, it is possible to specify all the margin properties in one property.
The css margin property is a shorthand property for the following individual margin properties:
margin-top is 12px
margin-right is 15px
margin-bottom 12px
margin-left 16px

div-box1 { margin: 12px 15px 12px 16px; }
If the margin property has three values:
margin: 12px 15px 14px;
top margin is 12px
right and left margins are 15px
bottom margin is 14px

div-box2 { margin: 12px 15px 14px; }
If the margin property has two values:
margin: 15px 20px;
top and bottom margin are 15px
right and left margin are 20px

div-box3 { margin: 15px 20px; }
If the margin property has one value:
margin: 16px;
all four margins are 16px

div-box4 { margin: 12px; }

CSS Margin auto alue

You can set the margin property to auto to horizontally center the element within its container.

div-box5 {
width: 320px;
margin: auto;
border: 1px solid blue;

CSS margin top, margin bottom, margin left, margin right, css margin 0 auto CSS Margin, top, bottom, left, righ, auto - css tutorial

820. CSS media - CSS tutorials - w3resource


2706. CSS Links - CSS tutorial
EchoEcho.Com : The complete CSS tutorial

2233. CSS Tutorial - Lists
The CSS list attribute allows you to customize the HTML list style and then use an image for the bullet mark. Here is a practical example that uses list style type:

2709. CSS Text - CSS tutorial
EchoEcho.Com : The complete CSS tutorial

2109. CSS Tutorial - Introduction to CSS
With the help of CSS we can create simple or complex websites, you can build that fancy design that you always like it.

3301. CSS font color, css tutorial
CSS font color css tutorial

Your add here
How to get PHP errors to display?
How to prevent sql injection in php mysqli
How do I get PHP errors to display - PHP error_reporting()
mysql_query(): The mysql extension is deprecated and will be removed i
Function eregi_replace() is deprecated in php - How to fix
PHP delete an element from an array
Uncaught Error: Call to undefined function MYSQL_NUM_ROWS() in
Deprecated: mysql_connect() mysql extension is deprecated and will be
mysqli_fetch_array() expects parameter 1 to be mysqli_result boolean g
SQL IN Operator - example
SQL like syntax and example
SQL WHERE AND & OR multiple conditions
SQL create table primary key autoincrement
PHP mysqli_connect () Function
SQL COUNT(), AVG() and SUM() Functions
Display data from SQL database with MySQLi into php - html table
SQL mysql order by columns, by date, by asc, by desc, random with PHP
PHP mysqli_query() Function - mysqli query
SQL delete row - SQL delete table
SQL update - SQL update select
Insert into SQL - Insert into table SQL - Insert data in sql
Login in PHP - simple login script with PHP MYSQL