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.
While this is what I want - this is what happens when you do a ctrl
+ -
manually in your browser.
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%.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With