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 :)
Use the float-right class in Bootstrap to place an element on the right.
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.
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>.
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.
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.
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).
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