Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fit image to screen height

Tags:

html

css

I'm trying to scale an image to the screen height. I'm using style="max-height:100%; width:auto; display: block;" to fit it to the screen height, and margin:0px auto; to center it. This work on Chrome browser but don't work on Firefox. I will be grateful for any help!

like image 207
Naourass Derouichi Avatar asked Oct 20 '25 15:10

Naourass Derouichi


1 Answers

What you are trying to do is fit the image size to the viewport's height, not the screen's.

The viewport is the actual portion of the screen where your app will be rendered (browser window - browser interface).

To achieve that, you could use height: 100vh, where one 1vh is equal to 1% of the viewport's height.

Thus, your image will always be exactly as tall as the viewport, that is the "screen" in your case.