What is vw in css

WBOY
Release: 2022-05-24 21:06:00
Original
4918 people have browsed it

In CSS, vw is a window unit and a relative unit, which means a percentage of the window width; vw is relative to the width of the window, and the window is the visible area of ​​the client browser. The window is divided into 100 units, and the size of 1vw is one percent of the width of the window.

What is vw in css

The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.

What is vw in css

CSS unit is a unit of measurement, including size units and color units. We often use facing units to avoid confusing the layout of the web page in different views.

vw is the abbreviation of Viewport's width. 1vw is always equal to one percent of the current viewport width. vw is a window unit and a relative unit. The viewport is divided into 100 units of vw relative to its width.

The advantage of vw is that it can directly obtain the width, but using % cannot correctly obtain the width of the visual area without setting the body width, so this is a good advantage.

The viewport here refers to the visible area of ​​​​the browser, as shown below:

What is vw in css

Sample code:

h1{font-size:8vw;}
Copy after login

If the view The width of the mouth is 200mm, then the font size of the h1 element in the above code will be 16mm, that is (8x200)/100

The example is as follows:

<html>
<style>
.p1{font-size:5vw;}
.p2{font-size:5px;}
</style>
</head>
<body>
<p class="p1">相对于viewport宽度大小的文字</p>
<p class="p2">px宽度大小的文字</p>
</body>
</html>
Copy after login

Output result:

What is vw in css

(Learning video sharing: css video tutorial)

The above is the detailed content of What is vw in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template