Reputation: 4722
I am trying to give an equal height to all the divs for various screen sizes. However on mobile of different screen sizes this doesn't work correctly
My code:
https://jsfiddle.net/90umLkak/
<div class="CustomList-customListContainer"><!-- react-empty: 292 --><section class="CustomList-header"><div class="CustomList-headerCont"><div class="CustomList-heartIcon"><img class="CustomList-imageTag" src="/static-listing/images/heart.svg" alt=""></div><div class="CustomList-Settings"></div><div class="CustomList-ListHeading"><button class="CustomList-ListHeading">My Favorites</button></div></div><div class="CustomList-itemsCount"><button class="CustomList-totalItems">7 items</button></div></section><div class="CustomList-imageContainer" style="width: 50%; height: 100%;"><a href="/savedlist?id=myFavorites"><img class="CustomList-imageTag" src="https://www.concordia.ca/students/health/_jcr_content/content-main/textimage/image.img.png/1462990904049.png" alt=""></a></div><div class="CustomList-imageContainer" style="width: 25%; height: 50%;"><a href="/savedlist?id=myFavorites"><img class="CustomList-imageTag" src="https://www.concordia.ca/students/health/_jcr_content/content-main/textimage/image.img.png/1462990904049.png" alt=""></a></div><div class="CustomList-imageContainer" style="width: 25%; height: 50%;"><a href="/savedlist?id=myFavorites"><img class="CustomList-imageTag" src="https://www.concordia.ca/students/health/_jcr_content/content-main/textimage/image.img.png/1462990904049.png" alt=""></a></div><div class="CustomList-imageContainer" style="width: 25%; height: 50%;"><a href="/savedlist?id=myFavorites"><img class="CustomList-imageTag" src="https://www.concordia.ca/students/health/_jcr_content/content-main/textimage/image.img.png/1462990904049.png" alt=""></a></div><div class="CustomList-imageContainer" style="width: 25%; height: 50%; background: rgb(241, 243, 244);"><a href="/savedlist?id=myFavorites" style="
width: 100%;
height: 100%;
display: block;
"><div class="CustomList-productsCount"><!-- react-text: 327 -->+ <!-- /react-text --><!-- react-text: 328 -->3<!-- /react-text --></div></a></div></div>
Upvotes: 0
Views: 50
Reputation: 2874
The rule which says height: 50%
doesn't work because there is no reference height. i.e - "50% of what?"
The solution is to set the height of the parent container. In your case, you have to set the height of the div with classname CustomList-customListContainer
explicitly.
If I may go one step ahead of your question, there are many other problems with your code. I'll list just four of them.
top: 37%
which doesn't work at all. You can't set the top value if the position
is relative
. Anyway, Shown below is an example on how to fix such issues, notice how I've added a parent div to the image div elements to fix the height of the container.
Upvotes: 0
Reputation: 15711
Your height styles are completely useless because the parent does not have an height. The reason why it seems to be working fine is because your images are scaled to size and they have a 1:1 size ratio, making the height correct.
Since the code you posted was absolutely unusable, I've given you a MINIMAL snippet to show how you can do.
.container {
width: 200px;
height: 100px;
}
.container .big {
height: 100%;
width: 50%;
}
.container div {
height: 50%;
width: 25%;
float: left;
border: 1px solid white;
background-color: blue;
box-sizing: border-box;
}
<div class="container">
<div class="big"></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
Upvotes: 2