How do I position link text in a which have the same size as it's container (so the whole container is clickable)? What would be the best way?
EDIT: I need to put text at the bottom of a container.
Here's my code. https://jsfiddle.net/6mnmf7z9/3/
How do I position link text in a which have the same size as it's container (so the whole container is clickable)? What would be the best way?
EDIT: I need to put text at the bottom of a container.
Here's my code. https://jsfiddle.net/6mnmf7z9/3/
https://jsfiddle.net/6mnmf7z9/10/
<a href=""><li>SIX</li></a>
ul li {
display: inline-block;
width: 120px;
border: 1px solid;
text-align: center;
padding-top: 57px;
padding-bottom: 1px;
}
May be you can try doing this
https://jsfiddle.net/oLf7ff6b/1/
You could use padding for it
a {
display:inline-block;
width:100%;
height:100%;
text-align:center;
padding-top: 70px;
}
A solution with flexbox:
ul li {
display:inline-block;
width:120px;
height:90px;
margin-bottom:5px;
border:1px solid;
}
a {
background:green;
width:100%;
height:100%;
display:flex;
align-items:flex-end;
}
<ul>
<li><a href="">ONE</a></li>
<li><a href="">TWO</a></li>
<li><a href="">THREE</a></li>
<li><a href="">FOUR</a></li>
<li><a href="">FIVE</a></li>
<li><a href="">SIX</a></li>
<li><a href="">SEVEN</a></li>
<li><a href="">EIGHT</a></li>
</ul>
EDIT
if you want to center the text horizontally add justify-content:center; to the link class
use display:table and float:lefttolias well as 'display:table-cell and vertical-align:bottom to a tag.
code:
ul li {
width: 120px;
height: 90px;
margin-bottom: 5px;
border: 1px solid;
display: table;
float: left;
}
a {
background: green;
display: table-cell;
vertical-align: bottom;
width: 100%;
height: 100%;
}
<ul>
<li><a href="">ONE</a>
</li>
<li><a href="">TWO</a>
</li>
<li><a href="">THREE</a>
</li>
<li><a href="">FOUR</a>
</li>
<li><a href="">FIVE</a>
</li>
<li><a href="">SIX</a>
</li>
<li><a href="">SEVEN</a>
</li>
<li><a href="">EIGHT</a>
</li>
</ul>
Jsfiddle: https://jsfiddle.net/6mnmf7z9/8/
If you are not supporting old IE browsers, you can use display: flex and align content like below example.
ul li {
width:120px;
height:90px;
margin-bottom:5px;
border:1px solid;
display:table;
float:left;
}
a {
background:green;
display:flex;
align-items:flex-end;
width:100%;
height:100%;
}
<ul>
<li><a href="">ONE</a></li>
<li><a href="">TWO</a></li>
<li><a href="">THREE</a></li>
<li><a href="">FOUR</a></li>
<li><a href="">FIVE</a></li>
<li><a href="">SIX</a></li>
<li><a href="">SEVEN</a></li>
<li><a href="">EIGHT</a></li>
</ul>