Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Zoom to Fit height and width (Stretch)

Tags:

html

jquery

css

My content is in a container of 800x480 pixels. When the window resizes, my goal is to:

  • Zoom/Stretch the container to fill the entire screen
  • Including all children of the container and maintain their relative positions
  • I don't care about maintaining the aspect ratio

So when the window width/height is 1600x960, I do the following:

zoom: 2

And this stretches the canvas, but if the new aspect ratio isn't the same as 800x480, then it won't fully stretch to either the height or the width.

Isn't something like this available, where I can set an individual stretch for the width and height?

zoom: (2, 2.5)
like image 794
P.Henderson Avatar asked Jun 26 '14 08:06

P.Henderson


People also ask

How do I stop a CSS layout from distorting when zooming in out?

To fix the problem with zooming in, try adding the min-width attribute to your outer countainer ( #container or #navbar ?). Setting min-width prevents the webpage from trying to shrink down beyond the specified width (i.e. 300px).

How do I stretch an image to fit CSS?

When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.

How do I make an image fit without stretching CSS?

You can use the css property object-fit . ("sets how the content of a replaced element, such as an <img> or <video> , should be resized to fit its container.") Related: object-position (specifies the alignment of an element's contents within its box.)


1 Answers

Viewport width-height might be what you need here

div#content{
    width: 100vw; // The width of this element is 100% of the viewports width
    height: 100vh; // The height of this element is 100% of the viewport height

    font-size: 1vmax; // You can fiddle with this to mame sure the font gets
                      // the size you want
}

If you want elements to maintain their relative positions, you can use the same rule for top and left css properties

While this is not supported by all browsers, polyfills are available here to make it work back to IE8

like image 86
Loupax Avatar answered Oct 05 '22 04:10

Loupax