Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left/Right float button inside div

Tags:

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.

enter image description here

like image 834
Mohd Shahril Avatar asked Aug 02 '13 00:08

Mohd Shahril


People also ask

How do I put the float button on the right side of a div?

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>.

How do I move a button from left to right in CSS?

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.

How do I fix the button on the right side in HTML?

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.


2 Answers

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;
}
like image 67
Ahmed Alaa El-Din Avatar answered Oct 15 '22 14:10

Ahmed Alaa El-Din


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>
like image 21
Penny Liu Avatar answered Oct 15 '22 15:10

Penny Liu