![]() |
VOOZH | about |
Setting viewport height and width in CSS helps create responsive and attractive webpage layouts. It allows elements to adjust according to the screen size of different devices.
CSS units such as pixels (px), percentages (%), and ems (em) allow to specify fixed or relative dimensions for elements based on the viewport size.
Example: Setting viewport height and width using CSS Units.
This approach ensures that elements scale proportionally with the viewport, offering a flexible and intuitive way to create responsive layouts. Viewport-relative units, including vh (viewport height) and vw (viewport width), enable developers to define element dimensions relative to the size of the viewport.
Example: Setting viewport height and width using Viewport-Relative Units.
Here, the .box element has a default height of 500px and adjusts to 50px on screens smaller than 768px using CSS media queries, demonstrating how to set viewport height and width dynamically based on screen size.
Example: Setting viewport height and width using CSS Media Queries.