简体   繁体   English

缩小页面 CSS

[英]Zoom out page CSS

I have a website that works perfectly when I zoom out my browser to 50% .我有一个网站,当我将浏览器缩小到 50%时,它可以完美运行。 But it is very bad on normal size ( 100% ).但它在正常尺寸( 100% )上非常糟糕。 I already use transform and zoom on the CSS but not being what I wanted CSS .我已经在 CSS 上使用了 transform 和 zoom 但不是我想要的CSS I cannot decrease font or image because of some reason.由于某种原因,我无法减少字体或图像。 All I want is to just make this page look like I zoom out the browser 50%.我想要的只是让这个页面看起来像我将浏览器缩小 50%。

Thanks for all your help.感谢你的帮助。

 <style type="text/css"> .navbar-brand{ position: absolute; width: 100%; left: 0; text-align: center; margin:0 auto; } .navbar-toggle { z-index:3; } .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropdown { position: relative; display: block; } .dropdown-content { display: none; position: absolute; right: 0; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown-content a:hover {background-color: #f1f1f1} .dropdown:hover .dropdown-content { display: block; } .dropdown:hover .dropbtn { background-color: #3e8e41; } @media (min-width: 1025px) { html { /* -webkit-transform: scale(2); -moz-transform: scale(2); transform: scale(2);*/ /* transform: scaleX(1) scaleY(.5);*/ } } @media (max-width: 600px) { #judul{ visibility: hidden; display: none } #menu{ display: none; } #menu-content{ display: block; position: relative; } #logo{ visibility: hidden; display: none; } </style>

You can use a non-css solution for this:您可以为此使用非 css 解决方案:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Viewport视口

But you can actually use CSS to zoom (but i dont recommend this for the entire page):但是您实际上可以使用 CSS 进行缩放(但我不建议将其用于整个页面):

 /* you can apply this on body aswell */ .zoomedElement { background-color: #CCF; zoom: 300%; } .scaledElement { background-color: #FAC; transform: scale(1.2); /* scales in all directions, probably not what you want but worth mentioning */ }
 <div class="zoomedElement"> <h6>Heading Zoomed</h6> Some text... </div> <div class="scaledElement"> <h6>Heading Scaled</h6> Some text... </div>

You can effectively render at 50% zoom by setting the body's width / height to 200% , but at 50% scale with transform .您可以通过将主体的width / height200%以 50% 缩放有效渲染,但使用transform50%缩放。 You'll also need to set the transform-origin to top left to avoid the scale transformation from shifting the top left corner of the body away from the top left corner of the window.您还需要将transform-origin设置为top left以避免scale变换将主体的左上角移离窗口的左上角。

This can be used for arbitrary zoom levels, just by using that proportion for scale , and the inverse of that proportion for width / height .这可以用于任意缩放级别,只需使用比例的scale ,以及width / height比例的倒数。

body {
  width: 200%;
  height: 200%;
  transform-origin: top left;
  transform: scale(50%);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM