I'm a beginner in HTML and CSS and I'm doing a freelance work for my course, but I ended up packing at one point. I have the following code in a snippet of my HTML:
<section id=#first>
<h1> Recomendações da semana </h1>
<ul>
<a href="http://myanimelist.net/anime/10793/Guilty_Crown" target="_blank">
<li><img src="img/gc.png"/><h2>Guilty Crown</h2></li>
</a>
<a href="http://myanimelist.net/anime/11757/Sword_Art_Online" target="_blank">
<li><img src="img/sao.png"/><h2>Item 1</h2></li>
</a>
<a href="http://myanimelist.net/anime/12189/Hyouka" target="_blank">
<li><img src="img/hyouka.png"/><h2>Hyouka</h2></li>
</a>
<a href="http://myanimelist.net/anime/11887/Kokoro_Connect" target="_blank">
<li><img src="img/kkr_con.png"/><h2>Kokoro Connect</h2></li>
</a>
</ul>
</section>
For the section, the height is automatic ( height: auto;
), as well as li
. What I want is that the height of these containers is equal to the height of the image, since h2
is above it. However, as the screen is resized, a white stripe is being added to the container (I believe it is the height + padding of h2
).
I would like to know how to ignore the height of h2
, leaving only the height of the image in the container.
Follow the code used in CSS:
#first{
width: 90%;
max-width: 1440px;
height: auto;
margin: 0 auto;
margin-bottom: 25px;
background-color: white;
overflow: hidden;
}
#first:after{
clear: both;
content: "";
display: block;
}
section h2{
width: 100%;
height: 35px;
margin: 0;
background-color: rgba(0, 0, 0, 0.6);
color: white;
font-family: calibri;
font-size: 18px;
font-weight: 100;
text-align: center;
padding-top: 12px;
position: relative;
bottom: 47px;
}
section ul{
margin: 0;
height: auto;
float: left;
width: 100%;
padding: 0;
list-style: none;
}
section ul a li{
float: left;
width: 25%;
height: auto;
max-height: 306px;
margin: 0;
overflow: hidden;
cursor:pointer;
}
section ul a li img{
width: 100%;
height: auto;
}
The final result with full screen:
Asthescreenisresizedandgetssmaller: