I only want the hovered element to be affected by its height. But all row items increase in height. What can i do to increase the height of the element that is just hovered ? (If there is a solution with javascript, it will be too)
Like in this link : https://www.hizliresim.com/cou4bn6
HTML and CSS codes:
.names {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.names div {
display: flex;
align-items: center;
flex-direction: column;
padding: 16px 0;
text-align: center;
}
.names div a {
font-size: 16px;
color: #25282e;
text-decoration: none;
}
.names div a:hover {
font-weight: 700;
}
.names div a:hover~img {
display: block;
}
.names div img {
width: 40px;
margin-top: 16px;
display: none;
}
<div >
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
</div>
Note : I've asked this question before, but the answer I approved was not exactly what I wanted (the image was hovering over the name below it, closing the text)
CodePudding user response:
Giving each of the name divs a height stops them from expanding to the size of the image, but then the names below obscure the images. As a solution I added z-index so the images display on top. Is that what you were trying to achieve?
No, I want any name elements not to be hidden. like this link hizliresim.com/cou4bn6 – furkancetkin
Okay, well in the example it looked like the names were partitioned in to 3 columns, so I have done that instead. The drawback of grid is the height of the rows are linked. If you just have one row per column, and each of those is a flex container, things get a bit easier. You could likely refactor to use flex for the .names container as well to help with responsiveness.
Updated snippet:
.names {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.names div div {
display: flex;
align-items: center;
flex-direction: column;
padding: 16px 0;
text-align: center;
}
.names div a {
font-size: 16px;
color: #25282e;
text-decoration: none;
z-index: 1;
}
.names div a:hover {
font-weight: 700;
}
.names div a:hover~img {
display: block;
z-index: 2;
}
.names div img {
width: 40px;
margin-top: 16px;
display: none;
}
<div >
<div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
</div>
<div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
</div>
<div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
<div><a href="#">Name</a><img src="https://picsum.photos/seed/picsum/200/300"></div>
</div>
</div>