[css] Left/Right float button inside div

How can I make button float only in div area?

Here is my example CSS and HTML.

_x000D_
_x000D_
.test {_x000D_
  width: 60%;_x000D_
  display: inline;_x000D_
  overflow: auto;_x000D_
  white-space: nowrap;_x000D_
  margin: 0px auto;_x000D_
}
_x000D_
<div class='test'>_x000D_
  <div style='float: left;'>_x000D_
    <button>test</button>_x000D_
  </div>_x000D_
  <div style='float: right;'>_x000D_
    <button>test</button>_x000D_
  </div>_x000D_
</div>
_x000D_
_x000D_
_x000D_

I want it to be like this.

enter image description here

This question is related to css html

The answer is


You can use justify-content: space-between in .test like so:

_x000D_
_x000D_
.test {_x000D_
  display: flex;_x000D_
  justify-content: space-between;_x000D_
  width: 20rem;_x000D_
  border: .1rem red solid;_x000D_
}
_x000D_
<div class="test">_x000D_
  <button>test</button>_x000D_
  <button>test</button>_x000D_
</div>
_x000D_
_x000D_
_x000D_


For those who want to use Bootstrap 4 can use justify-content-between:

_x000D_
_x000D_
div {_x000D_
  width: 20rem;_x000D_
  border: .1rem red solid;_x000D_
}
_x000D_
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />_x000D_
<div class="d-flex justify-content-between">_x000D_
  <button>test</button>_x000D_
  <button>test</button>_x000D_
</div>
_x000D_
_x000D_
_x000D_