CSS - 增加页面字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1386531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:02:35  来源:igfitidea点击:

CSS - Increase Page Font Size

css

提问by Villager

Possible Duplicate:
Allow users to change font size in a webpage

可能的重复:
允许用户更改网页中的字体大小

Hello,

你好,

I have some webpages. I would like the user to click an image and have the font-sizes of all of the content on the page increase. Is this possible? If so, how?

我有一些网页。我希望用户单击图像并增加页面上所有内容的字体大小。这可能吗?如果是这样,如何?

I know that the browsers have options inside of them. Basically, I want a way to do that in the page itself.

我知道浏览器里面有选项。基本上,我想要一种在页面本身中做到这一点的方法。

Thank you.

谢谢你。

回答by Matt Howell

Three things to achieve this:

实现这一目标的三件事:

Specify the overall font-size in the <body>tag. For example:

指定<body>标签中的整体字体大小。例如:

body { font-size: 100%; }

Don't use pixels to specify font-size anywhere else in the document.

不要使用像素来指定文档中其他任何地方的字体大小。

p.somePara { font-size: 120%; }
p.anotherPara { font-size: 1.4em; }

Attach an event handler to this image, to adjust the font size accordingly. Using jQuery, for example:

将事件处理程序附加到此图像,以相应地调整字体大小。使用jQuery,例如:

$("#largerTextImage").click(function() {
  $("body").css("fontSize", "120%");
});

Done.

完毕。

回答by ChrisW

If you increase the font size of a top-level element like <body>, then that [changed] size will be inherited by its child elements (assuming that other CSS rules for those element didn't override that size with an absolute value, which would also have messed up the user's changing font size in their browser).

如果您增加像 那样的顶级元素的字体大小<body>,那么 [已更改] 大小将被其子元素继承(假设这些元素的其他 CSS 规则没有使用绝对值覆盖该大小,这也将弄乱了用户在浏览器中更改的字体大小)。

This article(for example) says that it describes how to change CSS values programatically.

这篇文章(例如)说它描述了如何以编程方式更改 CSS 值。

回答by marcgg

I would say that you could switch css.

我会说你可以切换css。

Put all your font-sizes in a separated CSS file. Then duplicate this file and change the font sizes. Then use a piece of js script to swich css files.

将所有字体大小放在一个单独的 CSS 文件中。然后复制此文件并更改字体大小。然后使用一段js脚本来切换css文件。

There are a lot of tutorials up there that explain all about it. Here's one.

那里有很多教程可以解释所有相关内容。这是一个