24
loading...
This website collects cookies to deliver better user experience
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
width: 100%;
margin: 0 auto;
}
img {
width: 100%;
height: auto;
}
</style>
<body>
<div class="container">
<img src="ts.jpg" alt="" />
</div>
</body>
<head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
width: 100%;
position: relative;
padding-top: 56.25%;
}
.image {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
</style>
</head>
<body>
<div class="container">
<img class="image" src="./ts.jpg" alt="" srcset="" />
</div>
</body>
padding-top
. The value will depend on the aspect ratio.1920 X 1080 resolution
1080 / 1920 = 0.5625 --> The ratio
0.5625 * 100 = 56.25%
<style>
.container {
width: 100%;
position: relative;
padding-top: 56.25%;
}
</style>
<style>
@media screen and (max-width: 400px) {
.container {
padding-top: 100%;
}
}
</style>
padding-top
will be 100% because in a square height and width is the same. If you divide them you will get 1. And you know the rest.import React from 'react'
import Image from 'next/image'
const Responsive = () => {
return (
<div>
<Image
src='/ts.jpg'
height={9}
width={16}
layout='responsive'
objectFit='cover'
/>
</div>
)
}
export default Responsive