0

The following code properly places each button vertically stacked.

What is the way to insert spaces between them? Currently they are stuck to each other.

<html>
<head>
<style>

.buttonClass
{
    color: blue;
    background-color: yellow;
    
    display:block;
    width: 50px;
    border: 2px solid green;
}

</style>
</head>

<body>
<button class="buttonClass">one</button>
<button class="buttonClass">two</button>
<button class="buttonClass">three</button>
<button class="buttonClass">four</button>

</body>
</html>
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411

2 Answers2

3

Can't we use margin?

.buttonClass
{
    color: blue;
    background-color: yellow;
    display: block;
    width: 50px;
    border: 2px solid green;
    margin-bottom: 10px;
}
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="lib/style.css">
    <script src="lib/script.js"></script>
  </head>
  <body>
    <button class="buttonClass">one</button>
    <button class="buttonClass">two</button>
    <button class="buttonClass">three</button>
    <button class="buttonClass">four</button>
  </body>
</html>
1

You can use margin-bottom to put spaces between vertically stacked css buttons.

 <html>
<head>
<style>

.buttonClass
{
    color: blue;
    background-color: yellow;
    
    display:block;
    width: 50px;
    margin-bottom:10px;
    border: 2px solid green;
}

</style>
</head>

<body>
<button class="buttonClass">one</button>
<button class="buttonClass">two</button>
<button class="buttonClass">three</button>
<button class="buttonClass">four</button>

</body>
</html>

Your first intuition would be to use padding-bottom but using padding on buttons increases the distance between the text.

It is a good practice to use padding on buttons instead of width and height.

You can use margin-bottom or padding-bottom to put spaces between vertically stacked css buttons.



 <html>
<head>
<style>

.buttonClass
{
    color: blue;
    background-color: yellow;
    
    display:block;
    padding-left: 12.5px;
  padding-right:12.5px;
    margin-bottom:50px;
    border: 2px solid green;
}

</style>
</head>

<body>
<button class="buttonClass">one</button>
<button class="buttonClass">two</button>
<button class="buttonClass">three</button>
<button class="buttonClass">four</button>

</body>
</html>