Design comparison
Solution retrospective
The greatest challenge for me was dividing the card equally (50% image and 50% product description) and making the website responsive. ANY tips on the positioning and responsive aspects will be very appreciated, I'm still learning! Thank you so much for reading.
Community feedback
- @FelipeCastroDEVPosted about 2 years ago
para fazer essa divisão 50%/50% ficaria mais simples usar display grid
eu fiz algumas modificações no seu código, vou mandar aqui dai vc testa ai!
body { display: flex; justify-content: center; align-items: center; /* height: 100vh; Removido*/ background-color: var(--background-color); padding: 20px; /Adicionado/ }
.main.product-card { max-width: 600px; /* Colocamos um tamanho maximo no seu container */ display: grid; grid-template-columns: 1fr 1fr; /Principal comando para divisao 50% / 50%/ align-items: center; background-color: var(--card-and-btn-text-color); border-radius: 1rem; }
div.product-img { background: url("../images/product.jpg") no-repeat center; background-size: cover; width: 100%; height: 100%; border-radius: 1rem 0 0 1rem; }
div.product-details { display: flex; flex-direction: column; width: 100%; padding: 3rem; gap: 2rem; }
1fr equivalem a uma fração do espaço disponível na grid, sendo assim 1fr 1fr vai dividir o container em duas partes de 50% iguais, caso queira 1/3 seriam 1fr 1fr 1fr e assim vai.
Espero ter ajudado!!
A proposito gostei da sua solução com flex, parabéns.
Marked as helpful1@lichtlePosted about 2 years ago@FelipeAmorimDev muito obrigada pelas dicas, Felipe! Tinha pensado em usar o grid mas acabei usando o flexbox mesmo. Vou implementar as mudanças no meu código agora mesmo.
1 - @VCaramesPosted about 2 years ago
Hey there! 👋 Here are some suggestions to help improve your code:
Regarding your question,
You could used CSS Grid, since it automatically gives each side 50/50.
On the other hand, Flex only gives the content the necessary space they need. So you will need to to apply give each side a
width
of 50%.Here is a link to Google Developer’s site that will teach you how make your site's responsive:
-
The purpose of the Main Element is to identify the main content of your page. It is not the container of you component. After the main element, you want add a container to wrap you separate components in.
-
For this challenge you want to use the Picture Element not the Background Image Property. The Background Image Property is mainly used on decorative images
Picture Element will allow your to switch between images in different breakpoints and makes your site load faster by saving bandwidth.
Here is an example of how it works: EXAMPLE
Syntax:
<picture> <source media="(min-width: )" srcset=""> <img src="" alt=""> </picture>
More Info:
https://www.w3schools.com/html/html_images_picture.asp
https://web.dev/learn/design/picture-element/
-
The only heading in this challenge is the name of the product, “Caneca Happy Camper”. The rest of the text should be wrapped in a Paragraph Element.
-
The old price 🏷 is not being announced properly to screen readers. You want to wrap it in a Del Element and include a sr-only text explaining that this is the old price.
-
Implement a Mobile First approach 📱 > 🖥
With mobile devices being the predominant way that people view websites/content. It is more crucial than ever to ensure that your website/content looks presentable on all mobile devices. To achieve this, you start building your website/content for smaller screen first and then adjust your content for larger screens.
If you have any questions or need further clarification, let me know.
Happy Coding! 👻🎃
Marked as helpful1@lichtlePosted about 2 years ago@vcarames thank you so much for the tips, I'm already applying it to my code and will deploy soon. I'm having problems with the card sizing now, it's too big and I can't manage to make it smaller... :(
0@VCaramesPosted about 2 years ago@lichtle
I was about to check your component to fix the image issue you were having, but I saw you update the entire component. Great job! It looks awesome!
1@lichtlePosted about 2 years ago@vcarames thank you so much! I applied most of the things you teached me. I'm going to try implementing a mobile first approach on my next challenge and also search more about sr-only texts (I didn't apply them to my code yet).
0 -
- @FelipeCastroDEVPosted about 2 years ago
Esqueci de enviar as mudanças nos medias-queries rsrs
@media (max-width: 600px) { main.product-card { grid-template-columns: 1fr; /* 1fr para deixar o container todo em apenas uma coluna*/ }
div.product-img { min-height: 350px; background-position: center left; }
}
1
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