CSS Margin & padding

  Css margin:-

The Css margin properties are used to create space around elements, outside of any defined borders.

Syntax:-
Div
{
margin:70px;
}

Margin - individual sides

P {
Margin- top:100px;
Margin-bottom:100px;
Margin- right:100px;
Margin-left:100px;
}

Coding:-



Output is:-


Style 1:-

Syntax:-
h1
{
Margin:70px;
}

Coding:-




Output is:-



Style 2:-

Syntax:-
Div
{
Margin:70px 70px;
}
Coding:-




Output is:-



Style 3:-

Syntax:-
h1
{
Margin:70px 70px 70px 70px;
}

Coding:-



Output is:-


 Margin:25px 50px 75px 100px;
  • Top margin is 25px
  • Right margin is 50px
  • Bottom margin is 75px
  • Left margin is 100px
        Syntax:-
    P{
          Margin:25px 50px 75px 100px;
       }

Css padding:-

The Css padding properties are used to generate space
around  an element's content,inside of any defined borders.

With css,you have full control ever the padding.

There are properties for setting the padding for each side of an element top,right, bottom,and left.

Syntax:-
Div
{
Padding:100px;
}

Padding-individual sides
Padding-top
Padding-right
Padding-left
Padding-bottom

Coding:-



Output is:-


Style 1:-

Syntax:-
h2
{
Padding:100px;
}

Coding:-




Output is:-



Style 2:-

Syntax:-
h1
{
Padding:70px 70px;
}

Coding:-



Output is:-



Style 3:-

Syntax:-
h1
{
Padding:70px 50px 50px 70px;
}

Coding:-



Output is:-


Margin & Padding using by border :-

Syntax:-
Div
{
Border:solid 5px green;
Margin:50px;
Padding:50px;
}
Coding :-

<html>
   <head>
      <style type="text/css">
         .bob
          {
            border:solid 5px skyblue;
            padding-top:50px;
            padding-right:50px;
            padding-bottom:40px;
            padding-left:40px;
          }
          .kim
          {
            border:solid 5px red;
            margin-top:100px;
            margin-right:100px;
            margin-bottom:70px;
            margin-left:80px;
         }
</style>
<title></title>
</head>
<body>
<h1 class="bob">Example of margin
</h1>
<h1 class="kim">Example of padding
</h1>
</body>
</html>

Output is:-


Css table:-

1.border:solid;
2.width:500px; 
3.height:300px;
4.border-collapse:collapse;

Coding:-

<html>
<head>
<style type="text/css">
    table
        {
        border-collapse: collapse;
        width:500px;
        height: 300px;
        }
        table,td,th
        {
         border: solid 1px black;
        }
      td
        {
         text-align: center;
         vertical-align: bottom;
        }
      th
        {
         background-color: orange; 
        }
</style>
 <title>
 </title>
</head>
<body>
<table>
    <tr>
    <th colspan="4" >Employee Data</th>  
    </tr>
<tr>
<td>Emp Id</td>
<td>Name</td>
<td>Contact no</td>
 <td>salary</td>
 </tr>
    
    <tr>
<td>101</td>
<td>Soniya</td>
<td>5623478910</td>
 <td>20,000</td>
    </tr>
    
    <tr>
<td>102</td>
<td>taniya</td>
<td>2389916720</td>
 <td>22,000</td>
    </tr>
<tr>
<td>103</td>
<td>Riya</td>
<td>4323677215</td>
 <td>15,000</td>
    </tr>
    
</table>
</body>
</html>

Output is:-


By using hover effect:-

Coding:-

<html>
<head>
<style type="text/css">
    table
        {
        border-collapse: collapse;
        width:500px;
        height: 300px;
        }
        table,td,th
        {
         border: solid 1px black;
        }
      td
        {
         text-align: center;
         vertical-align: bottom;
        }
      th
        {
         background-color: orange; 
        }
      tr:hover
        {
          background-color: skyblue;
        }
</style>
 <title>
 </title>
</head>
<body>
<table>
    <tr>
    <th colspan="4" >Employee Data</th>  
    </tr>
<tr>
<td>Emp Id</td>
<td>Name</td>
<td>Contact no</td>
 <td>salary</td>
 </tr>
    
    <tr>
<td>101</td>
<td>Soniya</td>
<td>5623478910</td>
 <td>20,000</td>
    </tr>
    
    <tr>
<td>102</td>
<td>taniya</td>
<td>2389916720</td>
 <td>22,000</td>
    </tr>
<tr>
<td>103</td>
<td>Riya</td>
<td>4323677215</td>
 <td>15,000</td>
    </tr>
    </table>
</body>
</html>

Output is:-



Css table using by (odd &even number):-

Syntax:- even number

tr:nth-child (even)
{
Background-color:rgb(190,190,190);
}

Syntax:- odd number 

tr:nth-child (odd)
{
Background-color:rgb(171,231,221);
}

Coding :-

<html>
<head>
    <style type="text/css">
        table
        {
            border-collapse: collapse;
            border:dashed 1px grey;
            width:300px;
        }
        td,th
        {
            border: solid 1px black;
            text-align: center;
        }
         th
        {
           background-color: orange; 
        }
        tr:nth-child(even)
        {
            background-color:rgb(255,0,0);
        }
        tr:nth-child(odd)
        {
            background-color:rgb(17,231,221);
        }
</style>
 <title>
 </title>
</head>
<body>
<table>
    <tr>
    <th colspan="4" >Employee Data</th>  
    </tr>
<tr>
<td>Emp Id</td>
<td>Name</td>
<td>Contact no</td>
 <td>salary</td>
 </tr>
    
    <tr>
<td>101</td>
<td>Soniya</td>
<td>5623478910</td>
 <td>20,000</td>
    </tr>
    
    <tr>
<td>102</td>
<td>taniya</td>
<td>2389916720</td>
 <td>22,000</td>
    </tr>
<tr>
<td>103</td>
<td>Riya</td>
<td>4323677215</td>
 <td>15,000</td>
    </tr>
    </table>
</body>
</html>

Output is :-




Comments

Popular posts from this blog

Css basic Properties ✍🏻

Basic Html Notes

Advanced Html Notes