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.
If you want to move the button to the right, you can also place the button within a <div> element and add the text-align property with its "right" value to the "align-right" class of the <div>.
You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.
Answer: Use the text-right Class You can simply use the class . text-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.
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;
}
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With