Переопределить css flex align-content для ребенка - PullRequest
0 голосов
/ 08 ноября 2019

Как я могу переопределить align-content: flex-start для ребенка в модели flexbox? Я хочу переместить .Card__Bottom внизу моей карты. Или, может быть, я могу достичь этого без align-content: flex-start? Но когда я удаляю это свойство, я получаю больший межстрочный интервал

body {
  background: #dddddd;
  padding: 30px;
}

.Card {
  width: 320px;
  min-height: 200px;
  background: #fff;
  border-radius: 12px;
  padding: 30px 20px 20px 30px;
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
}

.Card__heading {
  margin: 0;
  flex-basis: 200px;
}

.Card__icon-wrapper {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.Card__description {
  margin: 10px 0;
}

.Card__action {
  margin: 0 0 10px;
  align-items: center;
  width: 100%;
}

.Card__bottom {
  align-self: flex-end;
}
<div class="Card">
  <h2 class="Card__heading">
    Heading
  </h2>
  <div class="Card__icon-wrapper">
    <span class="Card__icon">?</span>
  </div>
  <p class="Card__description">
    Description
  </p>
  <p class="Card__action">
    Action Text
  </p>
  <div class="Card__bottom">
    Bottom
  </div>
</div>

Ответы [ 2 ]

1 голос
/ 08 ноября 2019

Структура сетки здесь более уместна:

body {
  background: #dddddd;
  padding: 30px;
}

.Card {
  width: 320px;
  min-height: 200px;
  background: #fff;
  border-radius: 12px;
  padding: 30px 20px 20px 30px;
  display: grid;
  /* 3 Rows and the middle one taking the free space pushing the last one*/
  grid-template-rows: auto auto 1fr;
  /* 2 Columns and the first one taking the free space pushing the two other*/
  grid-template-columns: 1fr auto;
}

.Card__heading {
  margin: 0;
}

.Card__icon-wrapper {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.Card__description {
  margin: 10px 0;
}

.Card__action {
  margin: 0 0 10px;
  grid-column:span 2; /* Full width (span the 2 columns)*/
}

.Card__bottom {
  grid-column:span 2; /* Full width (span the 2 columns)*/
}
<div class="Card">
  <h2 class="Card__heading">
    Heading
  </h2>
  <div class="Card__icon-wrapper">
    <span class="Card__icon">?</span>
  </div>
  <p class="Card__description">
    Description
  </p>
  <p class="Card__action">
    Action Text
  </p>
  <div class="Card__bottom">
    Bottom
  </div>
</div>
0 голосов
/ 08 ноября 2019

Я добавлю дополнительный контейнер, разделяющий дно и верх

    <div class="Card">
<div class="Card__top">
      <h2 class="Card__heading">
        Heading
      </h2>
      <div class="Card__icon-wrapper">
        <span class="Card__icon">?</span>
      </div>
      <p class="Card__description">
        Description
      </p>
      <p class="Card__action">
        Action Text
      </p>
</div>
      <div class="Card__bottom">
        Bottom
      </div>
    </div>

и обменяю следующее css:

    .Card {
  width: 320px;
  min-height: 200px;
  background: #fff;
  border-radius: 12px;
  padding: 30px 20px 20px 30px;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...