font-optical-sizing
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.
Thuộc tính font-optical-sizing CSS đặt xem việc hiển thị văn bản có được tối ưu hóa để xem ở các kích thước khác nhau hay không.
Try it
font-optical-sizing: auto;
font-optical-sizing: none;
<section id="default-example">
<div id="example-element">
<h2>Chapter 3</h2>
<p>
On this particular Thursday, something was moving quietly through the
ionosphere many miles above the surface of the planet; several somethings
in fact, several dozen huge yellow chunky slablike somethings, huge as
office blocks, silent as birds.
</p>
</div>
</section>
@font-face {
src: url("/shared-assets/fonts/variable-fonts/AmstelvarAlpha-VF.ttf");
font-family: "Amstelvar";
font-style: normal;
}
#example-element {
font-family: "Amstelvar", serif;
text-align: left;
}
#example-element h2 {
font-size: 36px;
}
#example-element p {
font-size: 12px;
}
Cú pháp
/* Giá trị từ khóa */
font-optical-sizing: none;
font-optical-sizing: auto; /* mặc định */
/* Giá trị toàn cục */
font-optical-sizing: inherit;
font-optical-sizing: initial;
font-optical-sizing: revert;
font-optical-sizing: revert-layer;
font-optical-sizing: unset;
Các giá trị
Mô tả
Optical sizing được bật theo mặc định cho các font có trục biến thiên kích thước quang học. Trục biến thiên kích thước quang học được biểu diễn bằng opsz trong font-variation-settings.
Khi optical sizing được dùng, văn bản nhỏ thường được hiển thị với các nét dày hơn và chân chữ lớn hơn, trong khi văn bản lớn hơn thường được hiển thị tinh tế hơn với nhiều độ tương phản hơn giữa các nét dày và mỏng.
Định nghĩa hình thức
| Initial value | auto |
|---|---|
| Applies to | all elements and text. It also applies to ::first-letter and ::first-line. |
| Inherited | yes |
| Computed value | as specified |
| Animation type | discrete |
Cú pháp hình thức
font-optical-sizing =
auto |
none
Ví dụ
>Tắt optical sizing
<p class="optical-sizing">
This paragraph is optically sized. This is the default across browsers.
</p>
<p class="no-optical-sizing">
This paragraph is not optically sized. You should see a difference in
supporting browsers.
</p>
@font-face {
src: url("AmstelvarAlpha-VF.ttf");
font-family: "Amstelvar";
font-style: normal;
}
p {
font-size: 36px;
font-family: "Amstelvar", serif;
}
.no-optical-sizing {
font-optical-sizing: none;
}
Note: Font được tham chiếu ở trên — bao gồm optical sizing và được cấp phép tự do — rất tốt để kiểm thử. Bạn có thể tải về trên GitHub.
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| CSS Fonts Module Level 4> # font-optical-sizing-def> |