Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexbox center and bottom right item

Tags:

html

css

flexbox

I'm trying to achieve the following result using flexbox: Flexbox demo

I tried the with the following html but I can't get it to work.

<div class=" flex-center">
    <div class="flex-item-center">
        <p>
            Some text in box A
        </p>
    </div>
    <div class="flex-item-bottom">
        <p>Some text in box B....</p>
    </div>
</div>

CSS:

.flex-center {
  display: flex;
  align-items: center;
  align-content: center;
  justify-content: center;
}
.flex-item-center {
  align-self: center;
}

.flex-item-bottom {
  align-self: flex-end;
}

How can I make it look like the image?

like image 286
yeouuu Avatar asked Sep 04 '15 15:09

yeouuu


People also ask

How do I align items to the right in flexbox?

Alignment and flex-directionTry changing flex-direction: row-reverse to flex-direction: row . You will see that the items now move to the right-hand side.

How do you align left and right items in Flex?

The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.

Which flexbox property aligns items vertically?

Vertical align to center: The flexbox property is used to set the content to vertical align. The text content can be aligned vertically by setting the following display properties: align-items. justify-content.


1 Answers

Try:

#main-wrapper {
  background: blue;
  width: 100%;
  height: 100%;
  min-height: 300px;
  display: flex;
  align-items: center;
}

.x-center {
  display: flex;
  justify-content: center;
}

.y-center {
  flex: 1;
}

.x-right {
  justify-content: flex-end;
}

.y-bottom {
  align-self: flex-end;
}

.small-div {
  padding: 10px;
}
<div id="main-wrapper">
  <div class="x-center y-center small-div">Center center</div>
  <div class="x-right y-bottom small-div">Bottom Right</div>
</div>

Notes:

The align-self won't work for IE10 or below. Anybody know how to make the center div a bit more to the left without position relativing it? Thanks

like image 124
Linux4Life531 Avatar answered Sep 27 '22 21:09

Linux4Life531