-1

How can I align button groups, 3 buttons to the left and another 3 buttons to the right with an input field in the middle in a div.

<div class="container">
  <div>
    <div class="button-group">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>

  <div>
    <input type="text" name="textfield" value="">
  </div>

  <div>
    <div class="button-group">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>
</div>

Before: before applying your answer

after applying

This is how I want to arrange them

Rayan
  • 3
  • 3

2 Answers2

2

Flexbox solves your requirement. Learn more here

.container{
  display: flex;
  align-items: center;
  justify-content: space-around;
}
.button-group{
display:flex;
}
<div class="container">
  <div>
    <div class="button-group">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>

  <div>
    <input type="text" name="textfield" value="">
  </div>

  <div>
    <div class="button-group">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>
</div>
0

Like this?

.center{
  text-align: center;
}
.right{
  text-align: right;
}
<div class="container">
  <div>
    <div class="button-group">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>

  <div class="center">
    <input type="text" name="textfield" value="">
  </div>

  <div>
    <div class="button-group right">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>
</div>

Or do you mean like this? Source: (Making a flex item float right)

.button-container{
  display: flex;
}
.right{
  margin-left: auto;
}
.center{
  text-align: center;
}
<div class="container">
  <div class="button-container">
    <div class="button-group left">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
    <div class="button-group right">
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
      <button type="button" class="btn btn-secondary"></button>
    </div>
  </div>

  <div class="center">
    <input type="text" name="textfield" value="">
  </div>
  
</div>
Crimp
  • 389
  • 1
  • 22
  • I tried but unfortunately, it didn't work for me. I need three buttons to the right, three to the left, and the text field in the middle. I'm a beginner in HTML and CSS. – Rayan Aug 12 '22 at 20:24
  • thank you for your help, please, look at the screenshots after applying your answer to my case. I need you help please – Rayan Aug 13 '22 at 06:55