Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add offset on the right using bootstrap 4?

Tags:

Using Bootstrap 4 layout system, can I align my button with the textbox?

enter image description here

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row justify-content-center mb-4">
  <div class="col col-4">
    <input type="text"/>
  </div>
  <div class="col col-4">
    <input type="text"/>
  </div>
</div>
<div class="row justify-content-center mb-4">
  <div class="col">
  <input type="button" class="btn" value="Go"/>
  </div>
</div>
  

I know I can keep everthing inside the same row and align the button under the textbox... but then I need to adjust the spacing between them using a new css class... I was looking for a cleaner solution using the existing bootsrap 4 classes.

like image 505
Hooman Bahreini Avatar asked Jun 10 '18 01:06

Hooman Bahreini


2 Answers

If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line. - Bootstrap

Use a col-8 text-right for the the button's column.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row justify-content-center">
    <div class="col-4 ">
      <input type="text" class="form-control" />
    </div>
    <div class="col-4 ">
      <input type="text" class="form-control" />
    </div>
    <div class="col-8  text-right">
      <button type="button" class="btn btn-primary mt-4">Go</button>
    </div>
  </div>
</div>
like image 180
mahan Avatar answered Sep 28 '22 19:09

mahan


It looks like you want space between the columns. You can shrink the width of (col-3) the input columns and use an offset on the 2nd column...

<div class="container-fluid">
    <div class="row justify-content-center mb-4">
        <div class="col-3">
            <input class="mx-auto form-control" type="text">
        </div>
        <div class="offset-1 col-3 text-center">
            <input class="mx-auto form-control" type="text">
        </div>
    </div>
    <div class="row justify-content-center mb-4">
        <div class="col-7 text-right">
            <input type="button" class="btn" value="Go">
        </div>
    </div>
</div>

https://www.codeply.com/go/S33dvwVZxv

like image 22
Zim Avatar answered Sep 28 '22 18:09

Zim