css size样式

时间:2023-05-09 14:03:32

size 是一个 CSS 页面属性,用于指定打印页面的大小。该属性可以指定打印页面的宽度和高度,并且可以使用任何 CSS 长度单位来指定它们。

以下是一个 size 的示例:

<!DOCTYPE html>
<html>
<head>
<title>Size Example</title>
<style>
@page {
size: 8.5in 11in;
}
</style>
</head>
<body>
<h1>Page Content</h1>
<p>This is some text that will be printed.</p>
<p>This is some more text that will be printed.</p>
<p>This is even more text that will be printed.</p>
<p>This is the last paragraph on the page.</p>
</body>
</html>

在上面的示例中,使用 @page 规则为所有页面设置 size: 8.5in 11in,表示打印页面的宽度为 8.5 英寸,高度为 11 英寸。

除了使用具体的长度单位之外,还可以使用相对单位,例如 em、rem 或百分比。这些单位会相对于打印页面的默认大小进行计算。

<!DOCTYPE html>
<html>
<head>
<title>Size Example</title>
<style>
@page {
size: 50% 100%;
}
</style>
</head>
<body>
<h1>Page Content</h1>
<p>This is some text that will be printed.</p>
<p>This is some more text that will be printed.</p>
<p>This is even more text that will be printed.</p>
<p>This is the last paragraph on the page.</p>
</body>
</html>

在上面的示例中,使用 @page 规则为所有页面设置 size: 50% 100%,表示打印页面的宽度为视口宽度的 50%,高度为视口高度的 100%。

相关词 size