@elaineleung
Posted
Hi Daniel, your desktop view looks OK right now; I think you just need to fix the mobile view along with a few other things. I'll try to help :)
I'll first answer your question about why the two div containers are not the same size: Both divs are within the main container (meaning the main container is the parent), and the main container does not have a width set (aside from its default 100%). Because of that, it takes the width of the parent, which is the body, and which also is at 100%. Your image container has a height set, and the width would be based on that height since it's all proportional; your product info container's width is determined by its contents, which at the moment are stretching across the page in mobile mode. There needs to be an understanding about how boxes work and what determines their sizes; either the content determines the width of a box or the parent of the container.
How I would fix this: Create a new parent div container with a max-width on it. Instead of using the main container (which, as I said, is the parent container now of both divs), I'll have a new container that I call "card". The main container will be used instead as a container for providing padding to ensure the card doesn't hit the sides of the browser. Here's the structure:
<body>
<main>
<div class="card">
<div class="image container"></div>
<div class="product info"></div>
</div>
</main>
</body>
Here are the changes I then made:
- On
body
, changedisplay:flex
todisplay:grid
, and addplace-content: center
to center everything - On
main
: addpadding: 1rem
- On
card
: addmax-width: 420px
- On
product-image
: addobject-fit: cover
andwidth: 100%
to help with containing the image within its parent container so that the image's dimensions don't get distorted - On
product-info
: addflex-direction: column
andpadding: 1.5rem
. Remove all the left and right padding in every element, and add awidth: 100%
on the button. Things should be looking better by now.
For the desktop view, in your media query:
- On
card
: adddisplay:flex
,max-width:600
andheight: 100%
to the card container. - On
image-container
, addheight: 100%
- On
product-info
: Removeheight: 400px
and also remove thepadding-top
andpadding-bottom
in the children that's creating the extra vertical padding
I hope this helps to restore your sanity a bit. Keep practicing to make sure you develop a fundamental understanding of boxes and widths, and I hope to see an improved solution soon. Good luck!
Marked as helpful
@dan-ayalahdez
Posted
@elaineleung Very helpful, thanks a lot, Elaine.