Flex Example

by Kevin Pliester

HTML

<div class="flex-container">
  <div class="flex-item"><span>1</span></div>
  <div class="flex-item"><span>2</span></div>
  <div class="flex-item"><span>3</span></div>
</div>

SCSS

.flex-container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  justify-content: center; /* items werden zentriert, wenn alleine in einer spalte */
  /* justify-content: flex-start; /* items starten immer am anfang, wenn alleine in einer spalte */
  .flex-item {
    background-color: red;
    min-height: 150px;
    position: relative;
    @media screen and (min-width: 1080px) {
      flex: 1 33%;
    }
    @media screen and (max-width: 1079px) {
      flex: 0 50%; /* 0 = macht nicht automatisch width 100%, wenn item alleine in einer spalte */
    }
    @media screen and (max-width: 678px) {
      flex: 1 100%;
    }
  }
  span {
    color: #fff;
    font-size: 24px;
    top: 50%;
    left: 50%;
    position: absolute;
    transform: translateY(-50%) translateX(-50%);
  }
}