Я добавил align-items: center
, чтобы центрировать Link 2
по вертикали из-за очень длинного описания. Но это нарушило границу сетки. Как это можно исправить? Заранее спасибо. Полный код ниже:
table {
border: 1px solid #000;
border-collapse: collapse;
}
a {
color: red;
}
.tableRow {
position: relative;
display: grid;
text-decoration: none;
color: inherit;
grid-template-columns: repeat(2, 1fr);
/* place-items: center; */
border: 1px solid #000;
border-bottom: none;
align-items: center;
}
.tableRow:hover, .tableRow:focus {
background: #eee;
outline: none;
}
.tableRow:last-child {
border-bottom: 1px solid #000;
}
.tableRow a:not(.tableRowLink) {
position: relative;
z-index: 1;
}
.tableCell {
padding: 18px;
border-right: 1px solid #000;
}
.tableCell:last-of-type {
border-right: none;
}
.tableRowLink {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class = "table">
<div class = "tableRow">
<div class = "tableCell"><a href = "https://www.apple.com/" target = "_blank"><p>Link 1</p></a></div>
<div class = "tableCell"><p>Short Description</p></div>
<a class = "tableRowLink" href = "https://www.apple.com/" target = "_blank"></a>
</div>
<div class = "tableRow">
<div class = "tableCell"><a href = "https://www.google.com/" target = "_blank"><p>Link 2</p></a></div>
<div class = "tableCell"><p>Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description</p></div>
<a class = "tableRowLink" href = "https://www.google.com/" target = "_blank"></a>
</div>
</div>
Чтобы исправить это, вы можете вместо этого добавить align-content: center
к .tableCell
.
.tableRow {
position: relative;
display: grid;
text-decoration: none;
color: inherit;
grid-template-columns: repeat(2, 1fr);
border: 1px solid #000;
border-bottom: none;
}
.tableRow:hover, .tableRow:focus {
background: #eee;
outline: none;
}
.tableRow:last-child {
border-bottom: 1px solid #000;
}
.tableRow a:not(.tableRowLink) {
position: relative;
z-index: 1;
}
.tableCell {
padding: 18px;
border-right: 1px solid #000;
align-content: center;
display: flex;
align-items: center;
}
.tableCell:last-of-type {
border-right: none;
}
.tableRowLink {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class = "table">
<div class = "tableRow">
<div class = "tableCell"><a href = "https://www.apple.com/" target = "_blank"><p>Link 1</p></a></div>
<div class = "tableCell"><p>Short Description</p></div>
<a class = "tableRowLink" href = "https://www.apple.com/" target = "_blank"></a>
</div>
<div class = "tableRow">
<div class = "tableCell"><a href = "https://www.google.com/" target = "_blank"><p>Link 2</p></a></div>
<div class = "tableCell"><p>Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description Very Long Description</p></div>
<a class = "tableRowLink" href = "https://www.google.com/" target = "_blank"></a>
</div>
</div>
Вы имеете в виду выравнивание ссылок сверху? Просто удалите display: flex;
из .tableCell
Нет, я имел в виду минимизировать ширину первого столбца. Сейчас сетка разделена 50/50. Но первому столбцу не нужна ширина 50%. Он слишком широк для своего содержания. Есть ли способ сделать первый столбец таким же широким, как слова «Ссылка 1» и «Ссылка 2»? Спасибо.
Хорошо, попробуйте заменить это grid-template-columns: repeat(2, 1fr)
на grid-template-columns: auto 1fr;
в .tableRow
. Он должен создать два столбца с первой автоматической шириной
Я сделал. Это не идеально. Когда я заменяю «Ссылка 1» на «shortlink.com» и «Ссылка 2» на «verylonglink.com», ячейки имеют разную ширину. Смотрите здесь: ссылка
Любое исправление проблемы, описанной в моем предыдущем комментарии? Был бы очень признателен.
Извините, забыл вас спросить. Знаете ли вы, как сделать первый столбец (ссылка 1 и ссылка 2) подходящим для содержимого?