I have a snippet:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<header>
<div class="container">
<div class="row">
<div class="col-lg-3">
<div class="logo">
<img src="#" alt=" logotype">
</div>
</div>
<div class="col-lg-9">
<div class="head-buttons mr-auto">
<a href="">Русский</a>
<div class="auth-buttons">
<button>Войти</button>
<button>Регистрация</button>
</div>
</div>
</div>
</div>
</div>
</header>
I want col-lg-9 all content in this div align to right. Why mr-auto
is not working? How I can fix it? I tried and justify-content-end
on row, not working..
mr-auto is use to set margin-right auto not to use align content to right. you want to align content to right in col-lg-9 so you need to add class to text-right with col-lg-9. thank you. Save this answer.
me-auto means "margin end auto". Which is actually: margin-right: auto. me = margin-right and ms = margin-left.
auto-margins work for flexbox containers, but col-lg-9
isn't a flexbox container. Use d-flex
to make it a flexbox container, and then ml-auto
to push the content to the right.
<div class="row">
<div class="col-lg-3">
<div class="logo">
<img src="#" alt="logotype">
</div>
</div>
<div class="col-lg-9 d-flex">
<div class="head-buttons ml-auto">
<a href="">Русский</a>
<div class="auth-buttons">
<button>Войти</button>
<button>Регистрация</button>
</div>
</div>
</div>
</div>
Another option is to use col-lg-auto
to shrink the width of the right column to its content. Then ml-auto
on the column will work too.
<div class="row">
<div class="col-lg-3">
<div class="logo">
<img src="#" alt=" logotype">
</div>
</div>
<div class="col-lg-auto ml-auto">
<div class="head-buttons">
<a href="">Русский</a>
<div class="auth-buttons">
<button>Войти</button>
<button>Регистрация</button>
</div>
</div>
</div>
</div>
https://www.codeply.com/go/4n4R9cNrqE
mr-auto is use to set margin-right auto not to use align content to right.
you want to align content to right in col-lg-9 so you need to add class to text-right with col-lg-9.
thank you.
you should use class float-right and d-flex instead of mr-auto.
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