1
I’m a beginner in HTML and CSS and I’m doing a free theme work for my course, but I ended up getting stuck at one point.
I have the following code in an excerpt 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 Section, the height is automatic (height: auto;
), as well as for the li
. What I want is that the height of these containers is equal to the height of the image, since the h2
is above it. However, as the screen is resized, a white stripe is added to the container (I believe it is the height+padding of the h2
).
I wonder how I do to ignore the height of the 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 the full screen:
As the screen resizes and gets smaller:
You really solved the problem. As for the organization of the markings you have passed, it also solved another problem that arose after implementing the changes. Thank you very much!
– Frost
No @Frost :) probably the other problem must have been because of this:
<section id=#first>
in your HTML code that I modified and fixed for<section id="first">
in my answer. There were other mistakes too, but this was the most relevant. This type of markup errors can cause the code to crash or some CSS style to not be implemented correctly. Happy Coding =)– Chun