Как вставить ссылку в строку таблицы?
Всем привет! Как можно вставить ссылку в строку таблицы ну или еще какие есть варианты? Что бы можно было нажать в любом месте строки и что было понятно что это ссылка.
table {
width: 200px;
height: 30px;
}
tr {
background: #2F4F4F;
}
.left {
padding: 2px;
color: #FFF;
text-align: left;
font-size: 12pt;
}
.right {
padding: 2px;
color: #FFF;
text-align: right;
font-size: 12pt;
}
<table>
<tr>
<td class="left">Имя:</td>
<td class="right">Вася</td>
</tr>
<tr>
<td class="left">Имя:</td>
<td class="right">Петя</td>
</tr>
</table>
Ответы (2 шт):
Автор решения: Михаил Камахин
→ Ссылка
table {
width: 200px;
height: 30px;
}
tr {
background: #2F4F4F;
}
.left {
padding: 2px;
color: #FFF;
text-align: left;
font-size: 12pt;
}
.right {
padding: 2px;
color: #FFF;
text-align: right;
font-size: 12pt;
}
td a {
color: #fdc073;
transition: color 0.1s linear;
}
td a:hover {
color: #e96861;
}
<table>
<tr>
<td class="left">Имя:</td>
<td class="right">Фамилия: </td>
</tr>
<tr>
<td class="left">
<a href="https://css-tricks.com/">Вася</a>
</td>
<td class="right">Иванов</td>
</tr>
</table>
Или так
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.table {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
}
.table__item {
background-color: red;
position: relative;
color: white;
display: flex;
align-items: center;
justify-content: center;
padding: 15px;
}
.table__a {
color: inherit;
z-index: 1;
}
.table__a::before {
content: '';
display: block;
position: absolute;
background-color: black;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
transition: background-color 0.1s linear;
}
.table__a:hover::before {
background-color: rgba(0, 0, 0, 0.5)
}
<div class="table">
<div class="table__item">
<a class="table__a" href="https://css-tricks.com/">Ссылкаdsad asdsa das asd as</a>
</div>
<div class="table__item">
Ячейка таблицы
</div>
<div class="table__item">
Ячейка таблицы
</div>
<div class="table__item">
Ячейка таблицы
</div>
</div>
Автор решения: JonBrasers
→ Ссылка
Сделал так. Может кому пригодится, оставдю тут
a { text-decoration: none; }
a:visited { text-decoration: none; }
a:active { text-decoration: none; }
.tbl {
width: 200px;
color: #FFF;
margin: 8px 0 0 0;
border-radius: 10px;
display: flex;
Justify-content: center;
background: #444;
}
.left{
padding: 5px 8px;
text-align: left;
width: 100px;
}
.right{
padding: 5px 8px;
text-align: right;
width: 100px;
}
<a href="/user/id_1">
<div class="tbl">
<div class="left">Имя:</div>
<div class="right">Васек</div>
</div>
</a>
<a href="/user/id_2">
<div class="tbl">
<div class="left">Имя:</div>
<div class="right">Петька</div>
</div>
</a>