且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

放大DIV标签

更新时间:2023-12-05 08:08:46

我认为这是您需要的:

<style type="text/css">
html {height: 100%;}
body {margin: 0;padding: 0;height: 100%;}
.my-block {height:100%;}
</style>

查看实际情况: 100%的高度

但是,如果您想使"文本适应所有屏幕尺寸",则有一个问题.字体大小所用的百分比和EM单位完全相同(至少在理论上,尽管%在兼容性方面更好)-它们根据文本的实际大小(以像素为单位)缩放文本.换句话说,font-size:xx%不会根据其容器的高度或宽度来缩放文本,而是根据当前的文本大小来缩放.

However if you want to "adapt" your text "to all screen sizes" there is a catch. Percentage and EM units used with font-size do exactly the same (at least in theory, although % are better in terms of compatibility) - they scale text based on its actual size in pixels. In other words font-size:xx% does not scale text based on its container height or width but based on current text size.

请参见 css字体单位

您可以通过使用javascript实现所需的功能.但是,我建议您不要这样做.让用户决定是否需要放大/缩放.

干杯!