PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 14, 2022

[FIXED] How to scale a website so that it show same visible area for all viewports?

 July 14, 2022     css, frontend, html, javascript, web-deployment     No comments   

Issue

I made an website for an viewport 1366px*768px . Now I want that when I resize my browser then it should show same website in mobile or bigger screen without breaking design,I don't want responsive website .

Example :

  1. when I open website in 360px420px viewport then my website get scale down and show exact visible area as in 1366px768px without any scroll bar .
  2. when I open website in 2000px1000px viewport then my website get scale up and show exact visible area as in 1366px768px without any extra space .

I tried

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

 const siteWidth = 1366;
      const scale = screen.width / siteWidth;
      document
        .querySelector('meta[name="viewport"]')
        .setAttribute(
          'content',
          'width=' + siteWidth + ', initial-scale=' + scale + ''
        );
    }

By using above code I am able to scale website according to the width i.e 1366px on mobile device but on changing height it is showing extra space or scroll bar at the bottom. Also it is not working in desktop.

Any good solution so that I can scale my website correctly for all viewports?


Solution

The solution down below works, but you need to consider removing scrollbars or make fine adjustments to add scrollbars to scale.

<body>
  <div class="container">
    <!-- All other elements should be here -->
  </div>
</body>
body {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.container {
  width: 1366px;
  height: 768px;
}
const siteWidth = 1366;
const scale = window.innerWidth / siteWidth;

document.querySelector(".container").style.transform = `scale(${scale})`; 


Answered By - Bulent
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing