❤CSS New Units π₯: A Beginner's & New Units π Guide by Code Crushersπ£
CSS units are an essential part of web design. They allow you to define the size and position of elements on a webpage. Understanding the different types of CSS units is crucial to creating responsive and visually appealing websites. In this blog post, we'll take a look at the different types of CSS units and provide examples of how they can be used.
Absolute Units:-
Absolute units have a fixed size and do not change based on screen size or device. These units are useful for defining precise sizes for elements, such as font sizes or border widths.
Pixels (px)
Pixels are the most commonly used absolute unit in CSS. One pixel is equal to one dot on a screen, regardless of its density. For example, to set the font size of an element to 16 pixels, you would write:
font-size: 16px;
Points (pt)
font-size: 12pt;
Inches (in)
width: 3in;
Relative Units
Em (em)
font-size: 1.5em;
Rem (rem)
font-size: 1.5rem;
Viewport Units
Viewport Width (vw) and Viewport Height (vh)
height: 50vw;
width: 50vh;
Viewport Minimum (vmin) and Viewport Maximum (vmax)
Viewport minimum (vmin) and viewport maximum (vmax) are relative units that adjust to the minimum or maximum of the viewport width or height. To set the width of an element to the minimum of the viewport width or height, you would write:
width: 50vmin;
To set the height of an element to the maximum of the viewport width or height, you would write:
height: 50vmax;
Conclusion
In conclusion, understanding and using the appropriate CSS units is crucial for creating beautiful and functional websites. By choosing the right units for different design elements, designers can create layouts that are precise, scalable, and responsive to different screen sizes and devices. The use of absolute units, relative units, and viewport units offers designers flexibility and control over the appearance of their web pages.
By understanding and using the appropriate CSS units, designers can create beautiful and functional websites. Experimenting with different units can help you find the best approach for your design needs.
If you want to learn more about CSS units, check out our YouTube channel where we'll be exploring CSS units in more detail. Thanks for reading!
Author: CodeCrushers
YouTube Channel: Code Crushers
Comments
Post a Comment