CSS Сетка, как выровнять содержимое строки переменной высоты - PullRequest
1 голос
/ 13 апреля 2020

У меня есть структура из двух строк и четырех колонок, в которой есть строка переменной длины. При включенных автоматических строках строки могут вытягиваться для выравнивания содержимого. У меня есть кнопка и конец каждой сетки, которые я хотел бы выровнять по нижней части сетки. Может ли кто-нибудь помочь мне, если этого можно легко добиться с помощью сетки css?

html,
body {
  padding: 0;
  margin: 0;
}

input {
  font-size: 14px;
  font-family: Helvetica, sans-serif;
}

body {
  background-color: #BBB;
  font-family: Helvetica, sans-serif;
  padding-bottom: 100px;
}

h2,
h3 {
  margin: 0 0 .75em 0;
}


/* first example */

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-auto-rows: minmax(250px, auto);
}

.card {
  border-right: 2px solid grey;
  border-bottom: 2px solid grey;
  padding: 1em;
}

.grid {
  display: grid
}
<!-- first example -->
<div class="container">
  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    </p>
    <p class="grid"><button> Submit Me!</button></p>
  </div>

  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it.
    </p>
    <p class="grid"><button> Submit Me!</button></p>
  </div>
  <div class="card">
    <p>Lorem Ipsum

    </p>
    <p class="grid"><button> Submit Me!</button></p>
  </div>

  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>

    <p class="grid"><button> Submit Me!</button></p>

  </div>
  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type.

    </p>
    <p class="grid"><button> Submit Me!</button></p>

  </div>
  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    </p>
    <p class="grid"><button> Submit Me!</button></p>
  </div>

  <div class="card">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambledh the release of Letraset sheets containing
      Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

    </p>
    <p class="grid">
      <button> Submit Me!</button>
    </p>
  </div>
</div>

Вот кодовая ручка: https://codepen.io/awaisdar001/pen/wvKaEvx

1 Ответ

0 голосов
/ 13 апреля 2020

Добавьте это к своему коду:

.card {
    border-right: 2px solid grey;
    border-bottom: 2px solid grey;
    padding: 1em;

    /* new */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* pins flex items to opposite ends */
}

Это также работает:

.card {
    display: flex;
    flex-direction: column;
}

.grid {
    margin-top: auto; /* "pushes" flex item from the top, pinning it to the bottom */
}

пересмотренный кодовый блок

...