默认情况下使 HTML 页面缩放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22344246/
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
Making HTML page zoom by default
提问by Code
I've designed a page, where buttons look good when the browser zoom is at 90%, but by default other users view it at 100/125%+ in their browser which is resulting an overlap in buttons and input forms.
我设计了一个页面,当浏览器缩放为 90% 时,其中的按钮看起来不错,但默认情况下,其他用户在他们的浏览器中以 100/125%+ 的比例查看它,这导致按钮和输入表单重叠。
So, I want to set the zoom value as 90% by default when my JSP page loads.
所以,我想在我的 JSP 页面加载时默认将缩放值设置为 90%。
How do I do this? After making any such setting can make the page non-zoomable? Or Is there any better solution for this?
我该怎么做呢?进行任何此类设置后可以使页面不可缩放吗?或者有没有更好的解决方案?
回答by
Solved it as follows,
解决了如下,
in CSS
在 CSS 中
#my{
zoom: 100%;
}
Now, it loads in 100% zoom by default. Tested it by giving 290% zoom and it loaded by that zoom percentage on default, it's upto the user if he wants to change zoom.
现在,它默认以 100% 缩放加载。通过提供 290% 的缩放对其进行测试,并在默认情况下按该缩放百分比加载它,如果用户想要更改缩放比例,则由用户决定。
Though this is not the best way to do it, there is another effective solution
虽然这不是最好的方法,但还有另一种有效的解决方案
Check the page code of stack over flow, even they have buttons and they use un ordered lists to solve this problem.
检查stack over flow的页面代码,即使他们有按钮,他们使用无序列表来解决这个问题。
回答by Vasiliy Vanchuk
In js you can change zoom by
在 js 中你可以改变缩放
document.body.style.zoom="90%"
But it doesn't work in FF http://caniuse.com/#search=zoom
但它在 FF http://caniuse.com/#search=zoom 中不起作用
For ff you can try
对于 ff 你可以试试
-moz-transform: scale(0.9);
And check next topic How can I zoom an HTML element in Firefox and Opera?
并查看下一个主题如何在 Firefox 和 Opera 中缩放 HTML 元素?
回答by lucas.sa
A better solution is not to make your page dependable on zoom settings. If you set limits like the one you are proposing, you are limiting accessibility. If someone cannot read your text well, they just won't be able to change that. I would use proper CSS to make it look nice in any zoom.
更好的解决方案是不要让您的页面依赖缩放设置。如果你像你提议的那样设置限制,你就是在限制可访问性。如果有人不能很好地阅读您的文字,他们将无法改变这一点。我会使用适当的 CSS 让它在任何缩放中看起来都很好。
If your really insist, take a look at this question on how to detect zoom level using JavaScript (nightmare!): How to detect page zoom level in all modern browsers?
如果你真的坚持,看看这个关于如何使用 JavaScript 检测缩放级别的问题(噩梦!):如何在所有现代浏览器中检测页面缩放级别?