Bootstrap 4.1 Vertical Navs how to mr-auto/ml-auto badge

Bootstrap 4.1 Vertical Navs how to mr-auto/ml-auto badge



Is navs not navbar


navs


navbar



https://getbootstrap.com/docs/4.1/components/navs/#vertical



enter image description here


<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link A
<span class="badge badge-warning badge-pill">140</span>
</a>
</li>

<li class="nav-item">
<a class="nav-link" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link B
<span class="badge badge-warning badge-pill">300</span>
</a>
</li>
</ul>



tired change



<span class="badge badge-warning badge-pill">


<span class="badge badge-warning badge-pill">



to



<span class="badge badge-warning badge-pill ml-auto">


<span class="badge badge-warning badge-pill ml-auto">



but didn't work



Edited: see @Temani Afif answer below



if with d-flex only


d-flex



enter image description here



with d-flex align-items-center solved the problem


d-flex align-items-center



enter image description here






have you tried mr-auto?

– Chunbin Li
Sep 18 '18 at 0:03


mr-auto






yes ml-auto and mr-auto both not work

– kenken9999
Sep 18 '18 at 0:03




1 Answer
1



You need to make the a element a flex container to be able to use ml-auto/mr-auto. Simply add d-flex to a:


a


ml-auto


mr-auto


d-flex


a



I also added align-items-center to center but it's not mandatory:


align-items-center




.nav
background:pink;


<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" >
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link d-flex align-items-center" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link A
<span class="badge badge-warning badge-pill ml-auto">140</span>
</a>
</li>

<li class="nav-item">
<a class="nav-link d-flex align-items-center" href="#">
<i class="fas fa-angle-right fa-fw"></i>
Link B
<span class="badge badge-warning badge-pill ml-auto">300</span>
</a>
</li>
</ul>






thankyou so much, must add d-flex align-items-center to get this work, if only d-flex, the badge look something wrong

– kenken9999
Sep 18 '18 at 0:13


d-flex align-items-center






@kenken9999 it look stretched not wrong ;) because the default alignment is stretch

– Temani Afif
Sep 18 '18 at 0:21






anyways thankyou so much ;)

– kenken9999
Sep 18 '18 at 0:23



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)