Preston Preston - 6 months ago 20
HTML Question

Align items right within a flexbox

I am using bootstrap 4 and this css class to align vertically my items:

.vertical-align {
display: flex;
flex-direction: row;
}

.vertical-align > [class^="col-"],
.vertical-align > [class*=" col-"] {
display: flex;
align-items: center;
justify-content: flex-start;
}


in my HTML I have the following:

<div class="row vertical-align">
<div class="col-md-3">
<div class="logo">
<img src="assets/img/logo.png" alt="" class="img-responsive">
</div>
</div>
<div class="col-md-6">
<div class="catergorias">
<ul class="list-inline categorias_topo">
<li class="list-inline-item">
<a href="#">Categoria 1</a>
</li>
<li class="list-inline-item">
<a href="#">Categoria 2</a>
</li>
<li class="list-inline-item">
<a href="#">Categoria 3</a>
</li>
<li class="list-inline-item">
<a href="#">Categoria 4</a>
</li>
</ul>
</div>
</div>
<div class="col-md-3">
BUSCA
</div>
</div>


With this, all this content is aligned to the left.

How can I align, for example, the list (ul> li) to the right?

Nothing is working.

I have a fiddle: https://jsfiddle.net/xcottg08/

Answer

You should use justify-content: flex-end; instead of justify-content:flex-start to justify content to the right side.

You must specify it within these rules

.vertical-align > [class^="col-"],
.vertical-align > [class*=" col-"] {

However, I would create a new class like .vertical-align-right and one extra class to the container with list (the div above .catergorias with class .col-md-6), thus the code would look as follow:

.vertical-align-right > .list,
   justify-content: flex-end;
}
Comments