Design comparison
Solution retrospective
One thing I wasn't sure about here was how to make the profile picture always center on the verge of the card's bubbly background image. Finally I set the picture's top margin to be relative to the card's width but I'm sure it's not the driest solution since I had to adjust it with media queries anyway. I'm wondering now if it wouldn't be better to just go with fixed values in pixels on everything in the first place. I'd appreciate if anyone put their two cents in on this dilemma Edit: thanks to Ahmed-Elsayed I realised I have overcomplicated things unnecessarily and have already fixed that
Community feedback
- @Ahmed-Elsayed-projectsPosted about 2 years ago
Hello @AdamMintaj, -One way to do what you want and avoid media queries is to put the user information section and card's background inside a flex container. Then set each of them to
flex:1;
which will make them share the height in half. From here you can use two way to center the image:- Center the image horizontally with
text-align: center;
. Then center the image vertically by setting negative margin with half of the image height/width(doesn't matter since it's square-shaped) which in that case ismargin-top: -48px;
. - Use
position: relative;
on the information section. Then add this to the imageposition:absolute; left: 0 transform: translate(-50%, -50%) /*centers the image horizontally and vertically*/
Personally I do prefer the first method because I don't have to add margin padding-top to the information section(to prevent overlapping). Here's a link for my solution: https://www.frontendmentor.io/solutions/flexbox-and-background-styles-WL9A0tbLRn . Hope it helps
Marked as helpful0@AdamMintajPosted about 2 years ago@Ahmed-Elsayed-projects thanks a lot for your advice. You actually made me realise I totally overcomplicated the whole thing when it could be done so easily, thanks for that a lot. I will definitely change that. I also let myself check how you did the same challenge and I saw you put the scores in an unordered list. Since I just went with divs, I'm wondering why did you decide to use a list? What are the advantages of using a list here?
0 - Center the image horizontally with
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord