简体   繁体   English

调整网页大小以适合屏幕

[英]Resize web page to fit screen

I have a website which I want to follow the resizing of the browser window so that it always fits. 我有一个网站,我想按照浏览器窗口的大小进行调整,以使其始终适合。 I tried using css transform scale property with a ratio given by current window width divided by full-screen window width. 我尝试使用css转换比例属性,其比率为当前窗口宽度除以全屏窗口宽度。 It does re-scale but there must be something wrong with it because it leaves white blocks to the left and the right of the content (so it shrinks the site too much and then centers in in the window) Here is the javascript code: 它确实可以重新缩放,但一定有问题,因为它在内容的左右两侧留下了白色块(因此,它会使站点缩小太多,然后在窗口中居中)这是javascript代码:

$(window).resize(function(){
           var ratio = $(window).width()/1340;
                $('body').css('transform','scale('+(ratio)+')');
                $('body').css('-ms-transform','scale('+(ratio)+')');
                $('body').css('-moz-transform','scale('+(ratio)+')');
                $('body').css('-webkit-transform','scale('+(ratio)+')');
   });

Is there a better way to make the page fit the window (or make the scaling scale properly)? 有没有更好的方法来使页面适合窗口(或使缩放比例正确)?

To make your website mobile friendly, you should really think about making it responsive using media queries or using some front-end framework like Bootstrap, Foundation etc. 为了使您的网站移动友好,您应该真正考虑使用媒体查询或使用一些前端框架(如Bootstrap,Foundation等)使其具有响应能力。

Or if you just want to scale your website so it should not horizontally scale and fit to user's screen (No matter how small your UI component become) You can do that by adding following meta tag in your head section. 或者,如果您只是想缩放您的网站,那么它就不应水平缩放并适合用户的屏幕(无论您的UI组件有多小),都可以通过在标头部分添加以下元标记来实现。

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

It'll force browser to keep the website scale enough to fit the mobile screen width. 它将迫使浏览器保持网站规模足以适应移动屏幕宽度。

Hope It'll help. 希望会有所帮助。

you can use this, put the whole content inside it 您可以使用它,将整个内容放入其中

#wrapper{
    position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    overflow:hidden;
}

What you're wanting to do is build the website using Responsive and Adaptive methods. 您要做的是使用自适应和自适应方法来构建网站。 See if this link helps! 看看此链接是否有帮助! http://www.imediaconnection.com/content/33435.asp#singleview http://www.imediaconnection.com/content/33435.asp#singleview

Use 采用

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

in Html head section and 在HTML头部分和

@media only screen and
(min-device-width : screen px) and
(max-device-width : screen px) {
    #id{style}
}

in CSS. 在CSS中。

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

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