如何防止 html/css 上的文本大小增加
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5704646/
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
How do prevent text size increase on html/css
提问by zanona
this website looks very nice, although the've managed to prevent the user to increase/decrease the font size through the browser facility.
这个网站看起来很不错,虽然它已经设法阻止用户通过浏览器工具增加/减少字体大小。
If you check the Zoom Text Onlyoption on your browser and try to zoom in or zoom out (usually ?+ / ?- or ctrl+ / ctrl-)you can see that the font-size doesn't change.
如果您选中浏览器上的“仅缩放文本”选项并尝试放大或缩小(通常是 ?+ / ?- 或 ctrl+ / ctrl-),您会看到字体大小没有改变。
How can I replicate the same effect?
我怎样才能复制同样的效果?
I am thinking that this would be nice to prevent items from menu or purely layout based elements and leave only the main text be affected.
我认为这可以很好地防止菜单或纯粹基于布局的元素中的项目并只影响主要文本。
回答by thedaian
From looking at their CSS, it might be this line of code: -webkit-text-size-adjust:none;
If so, it'd only work in a limited number of browsers, not everywhere.
从他们的 CSS 来看,可能是这行代码:-webkit-text-size-adjust:none;
如果是这样,它只能在有限数量的浏览器中工作,而不是在所有地方。
There's not much reason you should be preventing users from adjusting text size, though. Yes, it might cause problems with the design, but you could also argue that the design should be flexible enough to deal with font size changes.
不过,没有太多理由应该阻止用户调整文本大小。是的,它可能会导致设计出现问题,但您也可能会争辩说设计应该足够灵活以应对字体大小的变化。
Comedy option: replace all your text with images.
喜剧选项:用图像替换所有文本。
回答by Kedarnath
Use the following CSS code.
使用以下 CSS 代码。
<style type="text/css">
-webkit-text-size-adjust:none;
-ms-text-size-adjust:none;
-moz-text-size-adjust:none;
text-size-adjust:none;
</style>