Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flexbox justify-self: flex-end not working? [duplicate]

Tags:

css

flexbox

I have a layout where sometimes the 'left' item is missing. In such cases, I still want the 'right' item to be right-aligned.

I thought I could do this with justify-self but that doesn't appear to be the case.

Is there a flexbox property for right-aligning one's self?

.row {    border: 1px solid black;    display: flex;    justify-content: space-between;    align-items: center;  }    .left,  .right {    display: inline-block;    background-color: yellow;  }    .right {    justify-self: flex-end;  }
<div class="row">    <!--<div class="left">left</div>-->    <div class="right">right</div>  </div>
like image 208
mpen Avatar asked Apr 04 '18 18:04

mpen


People also ask

Why there is no justify-self in flexbox?

Why are there no justify-items and justify-self properties? One answer may be: Because they're not necessary. The flexbox specification provides two methods for aligning flex items along the main axis: The justify-content keyword property, and.

Is there a justify-self CSS?

The CSS justify-self property sets the way a box is justified inside its alignment container along the appropriate axis.


1 Answers

You could use margin-left: auto on right element instead. Also when you use display: flex on parent element display: inline-block on child elements is not going to work.

.row {    border: 1px solid black;    display: flex;    align-items: center;  }  .left,  .right {    background-color: yellow;  }  .right {    margin-left: auto;  }
<div class="row">    <!--<div class="left">left</div>-->    <div class="right">right</div>  </div>
like image 164
Nenad Vracar Avatar answered Sep 29 '22 20:09

Nenad Vracar