So I am trying to make list items equal size and align inside content in the middle. All I get is a big mess. Also, another important thing I want the a tag link to work on the whole list element - so on the whole square. Right not the link only works if you press is on the a tag only. Is it possible to do it, without changing the HTML structure?
So the main things:
- The height of the
<li>item can vary, because of the contents inside, but not the width and I am trying to make all of them the same height. - Make the whole
<li>area clickable, so it would redirect to the<a>tag reference page. Without changing the current structure. - Center the content in
<li>tag and don't overflow the container. - In the example, the content inside the last
<li>element, the text, and the<a>tag is in the same line. How could I properly make them in different lines?
In the example below, it is the typical structure I need to style.
.ul {
display: flex;
}
.test1 {
display: inline-flex;
min-height: 100px;
width: 100px;
list-style: none;
background-color: #9affda;
color: black;
margin: 0px 10px;
border-radius: 10px;
align-items: center;
vertical-align: top;
}
<ul>
<li class="test1"><a href="">TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST</a></li>
<li class="test1"><a href="">TEST TEST TEST</a></li>
<li class="test1"><a href="">TEST TEST TEST</a></li>
<li class="test1">Test text </li>
<li class="test1">Test text <a href="">TEST TEST TEST TEST TEST TEST TEST</a></li>
</ul>
I have tried multiple approaches but every time something would go wrong [look at the main things I am trying to do]. I tried display table and table-cell, flex and inline-flex, inline-block and all other kinds of things...
Goal output
The blue squares are <li> elements. The <a> tag is called link inside and regular text is text inside.
