Reputation: 2327
How can I make button float only in div area?
Here is my example CSS and HTML.
.test {
width: 60%;
display: inline;
overflow: auto;
white-space: nowrap;
margin: 0px auto;
}
<div class='test'>
<div style='float: left;'>
<button>test</button>
</div>
<div style='float: right;'>
<button>test</button>
</div>
</div>
I want it to be like this.
Upvotes: 22
Views: 149152
Reputation: 17408
You can use justify-content: space-between
in .test
like so:
.test {
display: flex;
justify-content: space-between;
width: 20rem;
border: .1rem red solid;
}
<div class="test">
<button>test</button>
<button>test</button>
</div>
For those who want to use Bootstrap 4 can use justify-content-between
:
div {
width: 20rem;
border: .1rem red solid;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="d-flex justify-content-between">
<button>test</button>
<button>test</button>
</div>
Upvotes: 18
Reputation: 1833
Change display:inline to display:inline-block
.test {
width:200px;
display:inline-block;
overflow: auto;
white-space: nowrap;
margin:0px auto;
border:1px red solid;
}
Upvotes: 29