How to resize image according from screen resolution on html css

11.8k views Asked by At

I want to change an image so that its size is according to the screen resolution, for example 1920x1080 to 1600x900, using HTML and CSS.

How can I do it?

4

There are 4 answers

0
Harsh Makani On BEST ANSWER

HTML :

<div class="img-div">
<img src="path-to-image">
</div>

CSS :

.img-div { height:100%; width:100%;}
img { max-width:100% }
1
Shamil Yakupov On

You can use @media rule or set size of image in percents.

0
Abdulla Nilam On

use media Query. This will only works with relevant Screen resolution

@media only screen and (min-width: 1490px)
{
}
@media only screen and (max-width: 1490px) and (min-width: 1366px)
{
}
@media only screen and (max-width: 1366px) and (min-width: 1280px) 
{
}
@media only screen and (max-width: 1280px) and (min-width: 1024px) 
{
}
@media only screen and (max-width: 1024px) and (min-width: 768px) 
{
}
0
sanidhya chugh On

HTML

<img src="path of the image" alt="any message you want to type">

CSS

img {width: 15%; height: any numberpx;}

// make sure that you give the width of the image in terms of percentage that will adjust your image according to the size of the screen height you can give as per your need .