@fizasaif123
Posted
Use px for fixed-size elements and precise control. Use % for relative sizing within parent containers in responsive layouts. Use vh and vw for elements that should scale with the viewport size in responsive designs.
I had trouble with using CSS, when to use px, vh, or %
@fizasaif123
Posted
Use px for fixed-size elements and precise control. Use % for relative sizing within parent containers in responsive layouts. Use vh and vw for elements that should scale with the viewport size in responsive designs.
@george5-star
Posted
Congratulation Steven for completing the project and I hope you had fun building it. Regarding you question on which unit to use I recommend the using rem or em which is explained in the code samples below:
<div>
<h1>Some text</h1>
</div>
h1 {
padding: 1em; // which is equal to 16px and it is relative to its parent div.
}
h1 {
padding: 1rem; // this is relative to the root element which is the html tag.
}
So I recommend using em for paddings and margins and rem for font-sizes. Also this link will provide you with a brief overview on them.
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