Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 mr-auto not working correctly

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

like image 506
Mafys Grif Avatar asked Sep 07 '19 10:09

Mafys Grif


People also ask

Why is Mr auto 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.

What does me auto mean in Bootstrap?

me-auto means "margin end auto". Which is actually: margin-right: auto. me = margin-right and ms = margin-left.


Video Answer


3 Answers

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

like image 110
Zim Avatar answered Sep 26 '22 13:09

Zim


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.

like image 36
KuldipKoradia Avatar answered Sep 22 '22 13:09

KuldipKoradia


you should use class float-right and d-flex instead of mr-auto.

like image 22
Akshita Karetiya Avatar answered Sep 24 '22 13:09

Akshita Karetiya