Home > Back-end >  Placing buttons next to each other
Placing buttons next to each other

Time:06-30

Is there a way to place the buttons next to each other. For example below code places it below each other. Can we place it next to each other with a gap? Is there a way to achieve this?

.act_button span {
  color: black;
  width: 10vh;
}

.act_button {
  width: 200px;
  height: 100px;
  background-color: #ADD8E6;
  border: none;
  display: grid;
  grid-template-columns: auto auto;
  place-content: space-between;
}

.act_button>span {
  padding: 2px;
  margin-left: -2vh;
  margin-right: -1vh;
}
<button  type="button">
  <span>Top left</span>
  <span>Top right</span>
  <span>Bottom left</span>
  <span>Bottom right</span>
</button>

<button  type="button">
  <span>Top left</span>
  <span>Top right</span>
  <span>Bottom left</span>
  <span>Bottom right</span>
</button>

CodePudding user response:

Take advantage of flexbox. You can wrap your two buttons inside a div and then set that to display: flex; - this will get them to show next to each other.

Read more on Flex

.act_button span {
  color: black;
  width: 10vh;
}
.act_button {
  width: 200px;
  height: 100px;
  background-color: #ADD8E6;
  border: none;
  display: grid;
  grid-template-columns: auto auto;
  place-content: space-between;
}

.act_button>span {
  padding: 2px;
  margin-left: -2vh;
  margin-right: -1vh;
}

.button-wrapper {
  display:flex;
  gap: 20px;
}
<div >
  <button  type="button">
    <span>Top left</span>
    <span>Top right</span>
    <span>Bottom left</span>
    <span>Bottom right</span>
  </button>
  
   <button  type="button">
      <span>Top left</span>
      <span>Top right</span>
      <span>Bottom left</span>
      <span>Bottom right</span>
    </button>
  </div>

CodePudding user response:

You could wrap your buttons in a container and add display:flex; to the container CSS. Maybe something like this?

    <!DOCTYPE html>
<html>
<head>
<style>
.act_button span {
  color: black;
  width: 10vh;
}
.container{
  display:flex;
}
.act_button {
  width: 200px;
  height: 100px;
  background-color: #ADD8E6;
  border: none;
  display: grid;
  grid-template-columns: auto auto;
  place-content: space-between;
}

.act_button>span {
  padding: 2px;
  margin-left: -2vh;
  margin-right: -1vh;
}
</style>
</head>
<body>
<div >
  <button  type="button">
    <span>Top left</span>
    <span>Top right</span>
    <span>Bottom left</span>
    <span>Bottom right</span>
  </button>
  
   <button  type="button">
    <span>Top left</span>
    <span>Top right</span>
    <span>Bottom left</span>
    <span>Bottom right</span>
  </button>
</div>
</body>
</html>

CodePudding user response:

first of all you can wrap your two buttons with a div. The use css style in div with class like then style the class like: display:flex; margin right:20px; (that you need) or more style you can apply

  • Related