是否有html / css / javascipt方法来维护< div>在用户缩放页面时,以恒定的大小?也就是说,使用control-plus来增加文本大小,使用control-minus来减少它。
编辑:我想,踢球者是我想要< div>的 内容 保持相同的大小。
谢谢!
编辑:我的目标是(并且是)保留AdSense< div>从扩展到掩盖页面上的许多真实内容。但是来找出(谢谢你@thirtydot)真的没有好办法做到这一点。答案,对我来说(谢谢@Neal!):给< div>溢出:滚动以牺牲其内容而不是我试图展示的内容。
答案 0 :(得分:1)
我不确定你的意思,只需使用css:
div#id {
width: 100px; /*or some other #*/
height: 100px; /*or some other #*/
}
HTML:
<div id="id">some content</div>
答案 1 :(得分:1)
没有好办法(阅读:可靠)来做到这一点。遗憾。
您要求的内容基本上归结为检测浏览器的缩放级别,这里有一个很好的答案(确认这有多难):
正如答案中所述,有一种“有点”的跨浏览器疯狂方式涉及使用Flash,但有一些缺点:
无论如何,它在这里:
http://blog.sebastian-martens.de/2009/12/how-to-detect-the-browser-zoom-level-change-browser-zoo/
答案 2 :(得分:1)
要使缩放的div大小不变(但不是其中的内容),请执行以下操作:
在你的css里面为那个div:
min-width:100%;
最大宽度:100%;
这会冻结宽度,你也可以对高度做同样的事情。
答案 3 :(得分:1)
.box {
background: red;
width: 5vw;
height: 10vh;
position: absolute;
top: 10vh;
left: 5vw;
}
<div class="box"></div>
答案 4 :(得分:0)
您应该能够使用px测量来设置css的宽度和高度
例如
div
{
width:100px; height:200px;
}
答案 5 :(得分:0)
我在另一篇文章中读到了一个我还没有测试的解决方案......
Maintain div size (relative to screen) despite browser zoom level
使用过的javascript:
//This floating div function will cause a div to float in the upper right corner of the screen at all times. However, it's not smooth, it will jump to the proper location once the scrolling on the iPhone is done. (On my Mac, it's pretty smooth in Safari.)
function flaotingDiv(){
//How much the screen has been zoomed.
var zoomLevel = ((screen.width)/(window.innerWidth));
//By what factor we must scale the div for it to look the same.
var inverseZoom = ((window.innerWidth)/(screen.width));
//The div whose size we want to remain constant.
var h = document.getElementById("fontSizeDiv");
//This ensures that the div stays at the top of the screen at all times. For some reason, the top value is affected by the zoom level of the Div. So we need to multiple the top value by the zoom level for it to adjust to the zoom.
h.style.top = (((window.pageYOffset) + 5) * zoomLevel).toString() + "px";
//This ensures that the window stays on the right side of the screen at all times. Once again, we multiply by the zoom level so that the div's padding scales up.
h.style.paddingLeft = ((((window.pageXOffset) + 5) * zoomLevel).toString()) + "px";
//Finally, we shrink the div on a scale of inverseZoom.
h.style.zoom = inverseZoom;
}
//We want the div to readjust every time there is a scroll event:
window.onscroll = flaotingDiv;