Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css Image Resize based on height

Tags:

html

css

image

I am aware of resizing images bases on width:

img{
  max-width: 100%;
  height: auto;
}

or

img{
  width: 500px;
  height: auto;
}

Is there a way to do it by height? This does not seem to work:

img{
  height: 500px;
  width: auto;
}

How can I do this?

like image 282
Tithos Avatar asked Mar 13 '14 20:03

Tithos


2 Answers

From what you have shown it should work fine.

img{
  height: 500px;
  width: auto;
}

The above code does work, make sure it's not in a restrictive div, or another style is overwriting it

like image 127
datatest Avatar answered Sep 22 '22 14:09

datatest


You in fact can explicitly declare a height of 100px (for example) with height: 100px;. If your code isn't working this way, there may be something else outside of this context that is causing the problem.

like image 27
TylerH Avatar answered Sep 23 '22 14:09

TylerH