Related Articles

Related Articles

How to tab space instead of multiple non-breaking spaces (nbsp)?
  • Last Updated : 30 Apr, 2019

In CSS property padding and margin can be used to tab space instead of non-breaking spaces (nbsp).

By using padding property :

By using padding property we can give any amount of spaces in any direction of an element (i.e, top, right, bottom, left) from the border of the element. Here we only deal with the spaces so we need only two padding property i.e, padding-left and padding-right.

Syntax :

 
padding-left : value;
or
padding-right : value;

Parameter : No parameter required.



Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
<script src=
</script>
    <style>
        div {
            width: 300px;
            height: 100px;
            background-color: red;
        }
          
        P {
            width: 100px;
            height: 100px;
            background-color: green;
            text-align: center;
            font-weight: bold;
        }
    </style>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("#demo").css("padding-left", "30px");
            });
        });
    </script>
</head>
  
<body>
  
    <div id="demo">
  
        <p> Block 1 </p>
  
        <button>Submit</button>
    </div>
  
</body>
  
</html>

chevron_right


Output :
Before Click.

After Click.

By using margin property :

By using margin property we can give any amount of spaces in any direction of an element (i.e, top, right, bottom, left) from the border of the element. Here we only deal with the spaces so we need only two margin property i.e, margin-left and margin-right.

Syntax :

 
margin-left : value;
or
margin-right : value;

Parameter : No parameter required.

Example :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
<script src=
</script>
    <style>
        div {
            width: 300px;
            height: 100px;
            background-color: red;
        }
          
        P {
            width: 100px;
            height: 100px;
            background-color: green;
            text-align: center;
            font-weight: bold;
        }
    </style>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("#demo").css("margin-left", "60px");
            });
        });
    </script>
</head>
  
<body>
  
    <div>
  
        <p id="demo"> Block 1 </p>
  
        <button>Submit</button>
    </div>
  
</body>
  
</html>

chevron_right


Output :
Before Click.

After Click.

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :