1

I'm trying to make an entire cell of my table clickable and I've tried just about every solution I found here except whenever my table cell is finally a hyperlink, the text just will not center no matter what I do and I could use some help.

Here's my html:

table {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
}

td a {
  color: #333;
  display: flex;
  height: 100%;
  width: 100%;
  justify-content: center;
}
<table align="center" border="1">
  <tr>
    <td><a href="#">home</a></td>
  </tr>
</table>

And here's the CSS for it:

And here's a visual of what it looks like:

enter image description here

Sorry if this is something that's been asked and answered, I just personally couldn't find a solution on here after three days of searching. Thanks to anyone that helps!

Bhuwan
  • 16,525
  • 5
  • 34
  • 57
  • Did not understand. What is your question exactly? – vaishali kapadia Jan 22 '18 at 06:16
  • 1
    Searching far less than three days got me: [This](https://stackoverflow.com/questions/10070232/how-to-make-a-cell-of-table-hyperlink), [this](https://stackoverflow.com/questions/3337914/how-can-i-make-a-link-from-a-td-table-cell) and [this](https://stackoverflow.com/questions/3966027/make-link-in-table-cell-fill-the-entire-row-height/3966257#3966257). – SpazzMarticus Jan 22 '18 at 06:20
  • 1
    Possible duplicate of [Make link in table cell fill the entire row height](https://stackoverflow.com/questions/3966027/make-link-in-table-cell-fill-the-entire-row-height) – SpazzMarticus Jan 22 '18 at 06:21

4 Answers4

1

No need to use flex here. Just set display:block to your anchor tag and add some padding for spacing.

Stack Snippet

table {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
}

td a {
  color: #333;
  display: block;
  padding: 20px;
  text-align: center;
}
<table align="center" border="1">
  <tr>
    <td><a href="#">home</a></td>
  </tr>
</table>
Bhuwan
  • 16,525
  • 5
  • 34
  • 57
1

use align-items: center; in anchor tag

table {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
}

td a {
  color: #333;
  display: flex;
  height: 100%;
  width: 100%;
  justify-content: center;
  align-items: center;
}
<table align="center" border="1">
  <tr>
    <td><a href="#">home</a></td>
  </tr>
</table>
satyajit rout
  • 1,623
  • 10
  • 20
0

table {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
}

td a, td a:link, td a:hover {
  display:block;
  color: #333;
  padding:40px;
  text-align:center;
  justify-content:center;
}
<table align="center" border="1">
  <tr>
    <td><a href="#">home</a></td>
  </tr>
</table>

This should work for you. You don't need to break out the flexbox, and you don't need to make the td a width:100% height:100%. If you just set those properties for the table, the td a will stretch.

Tanner Babcock
  • 3,232
  • 6
  • 21
  • 23
0

use this:

td a{text-align: justify;}