0

I want to know how can I extend the image to the part ([) marked in black. This is my code (I'm trying to make it responsive):

body {
  background: #aeddd5;
}

.main {
  max-width: 900px;
  margin: auto;
}

img {
  width: 100%;
  height: 100%;
}
<body>

  <div class="main">
    <img src="./img/cf60903b8674148b9ab6ba194833fd2f_page-0001.jpg">
  </div>

</body>

What I have

SS

I want to have something like this:

SS

dippas
  • 58,591
  • 15
  • 114
  • 126
mochi
  • 3
  • 2
  • 1
    How do you want to rescale your image to fit the height? Do you want it to stretch? Do you want to resize with the same aspect ratio? More details have to be provided – Geeky Quentin Jul 09 '22 at 02:41
  • Maybe [this post using viewport-percentage lengths](https://stackoverflow.com/questions/1575141/how-to-make-a-div-100-height-of-the-browser-window). Flexbox can also work with the parent having `flex-direction: column;` and the child with `flex-grow: 1;` I think – Anthony L Jul 09 '22 at 02:46
  • yes, i want to resize with the same aspect ratio. I want the entire page to look like the second image – mochi Jul 09 '22 at 03:00
  • As the image is not having the required height as the screen , it is not possible to attain the desired result. The best thing what i can suggest is , you want to keep the aspect ratio same . So for that, just align the image to the center of the screen . – krishnaacharyaa Jul 09 '22 at 03:10

4 Answers4

1

Seems like you want to stretch the image for all screen views.

body {
  background: #aeddd5;
}

.main {
  max-width: 900px;
  margin: auto;
}

img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

@media only screen and (max-width: 600px) {
  img[data-width="1024"] {
    height: 100vh;
  }
  img[data-width="1440"] {
    height: 100vh;
  }
}
<div class="main">
  <img src="https://th.bing.com/th/id/OIP._HNl_Hk5V4UVNVikQTEvaQHaKb?pid=ImgDet&w=169&h=237&c=7" data-width="1024" data-height="768" />
</div>
dippas
  • 58,591
  • 15
  • 114
  • 126
Sachin Som
  • 1,005
  • 3
  • 8
1

You can stretch the image with the object-fit property, add display: block to the image for eliminate the excess space left by the images for being inline elements and declared a size coverting all the page with the relative length units vh and vw

body {
  margin: 0;
}

img {
  display: block;
  object-fit: cover;
  height: 100vh;
  width: 100vw;
}
<div class="main">
  <!-- Example image -->
  <img src="https://pbs.twimg.com/media/EzueaqPVgAEIPgd?format=jpg&name=large">
</div>
dippas
  • 58,591
  • 15
  • 114
  • 126
MART3
  • 31
  • 6
0

Change height:100% to height:100vh and add object-fit:cover

body {
  background: #aeddd5;
  margin: 0;
}

.main {
  max-width: 900px;
  margin: auto;
}

img {
  width: 100%;
  height: 100vh;
  object-fit: cover;
  display: block;
}
<div class="main">
  <img src="https://picsum.photos/400/1200">
</div>
dippas
  • 58,591
  • 15
  • 114
  • 126
0

HTML:-

<html>
<head>
<title>Your Title</title>
<style>
body{
    background: #000000;
}
.main{
  max-width:900px;
  margin: auto;
}
img{
  width:100%;
  height:100%;
  padding: 2%;
  background-color: #ffffff;
}
.outborder{
    background: #aeddd5;
    padding: 1%;
}
</style>
</head>
<body>
  <div class="outborder">
    <div class="main">
      <img src="./img/cf60903b8674148b9ab6ba194833fd2f_page-0001.jpg">   
     </div>
  </div>
</body>
</html>

I guess this should work out for you. I just made another division for the aqua color and changed the body color to black. Added some padding & color to image background.