Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale down a webpage to 90%

When you press Ctrl+- on any browser, the page scales down to 90% of it's original size. I need to replicate that, and open my webpage at 90% of it's original by default, instead of 100% because it looks nicer at 90%.

I tried the most common approach as mentioned here, here, and here, all of which basically tell you to add this block of code in your css.

html
{
    zoom: 0.9; /* Old IE only */
    -moz-transform: scale(0.9);
    -webkit-transform: scale(0.9);
    transform: scale(0.9);
}

The problem with this is that it creates a gap on the left and the right sides, as well as a huge gap on the top, which aren't present when you manually reduce the size by doing a ctrl+-.

This is what happens when I use the above mentioned code - notice the gaps on the left, right, top. This is what happens when I use the above mentioned code

While this is what I want - this is what happens when you do a ctrl+ - manually in your browser. While this is what I want - this is what happens when you do a ctrl -.

How do I go about this?

EDIT: As Jonathon said in the comments, if my page looks nicer at 90%, I should have designed it to be that way instead of having to scale down. The problem was that I'm using this default template, and I just prefer it at 90% over the full 100%.

like image 222
Randomly Named User Avatar asked Aug 25 '15 16:08

Randomly Named User


People also ask

How do you scale down in HTML?

One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.

How do I resize an entire page in HTML?

If you set the width to 100% on the body element you will have a full page width. This is essentially equivalent to not setting a width value and allowing the default. If you want to use the body element as a smaller container and let the HTML element fill the page, you could set a max-width value on the body.

How do I scale down CSS?

scale() The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.


1 Answers

You need to use/convert to relative units in your CSS. Either % or em or rem.

Then at the body level you can set an absolute size that results in the relative measures recalculating to what you want.

If you use em or ex exclusively: You declare font-size: 90% for body and you'll be able to adjust on the fly.

It all comes down to the units you choose and making them relative will allow you the kind of freedom you are looking for now.

like image 131
Matt Avatar answered Oct 08 '22 05:10

Matt