Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 float-right inside .row

I'm new to Bootstrap 4 and can't seem to get float-right on a col div working within a row. Here's my code:

<div class="row" > <div class="col-md-8 float-right" style="border: 1px solid red;"> <h3>Five grid tiers</h3> <p>Hi</p>  </div> </div> 

Weirdly it works fine without the row as a parent div, but I'd like to use the row. Am I missing something?

Thanks :)

like image 374
Zazz Blammymatazz Avatar asked Jan 15 '18 23:01

Zazz Blammymatazz


People also ask

How do I float a column right in Bootstrap?

Use the float-right class in Bootstrap to place an element on the right.

How do I float a button right in Bootstrap?

Bootstrap allows us to align elements by using the utility class float. As we want to align the button to the right side of the text box, we have to use the float-right class.

How do you float a button to the right?

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 an element to the right in Bootstrap?

float-left class is used to float the element to the left. The . float-right class is used to float the element to the right.


2 Answers

row is a flex container in bootstrap-4, to align content in flex-container you need to use ml-auto and mr-auto.

Here's the example:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">  <div class="row ml-1">    <div>       Hello from left    </div>    <div class="ml-auto mr-3">       Hello from right    </div>  </div>

Here's the official docuemtation link and example: https://getbootstrap.com/docs/4.0/utilities/flex/#auto-margins

For cases like when flex container is not being used, you can use float-right which is equivalent of pull-right in previous versions.

There is also an utility Justify Content to change alignment of items in flex container.

like image 170
Jainik Avatar answered Sep 17 '22 11:09

Jainik


Bootstrap 4 has incorporated Flexbox for their layouts. You can get your desired result by adding the class 'justify-content-end' to the parent container.

<div class="row justify-content-end" >    <div class="col-md-8" style="border: 1px solid red;">      <h3>Five grid tiers</h3>      <p>Hi</p>    </div>  </div>

If you want to learn the basics of Flexbox, I recommend checking out this quick and fun tutorial: http://flexboxfroggy.com/. It's a great system, though it is not supported in Legacy IE (IE 9 and earlier).

like image 24
Soren Baird Avatar answered Sep 17 '22 11:09

Soren Baird