Home > Mobile >  How to fix image position in mobile view?
How to fix image position in mobile view?

Time:02-22

My website looks like this - Website

But the mobile view of the same site looks like this

HTML Part -

<div >
    <img src="girl.png">
</div>

CSS Part -

.content .imgBox{
    
    object-fit: cover;
    height: 800px;
    display:flex;
    justify-content:flex-end;
    position: relative;
    left: 100px;
    top:100px
    
}

CodePudding user response:

Learn about responsive layout and media query in CSS, here tutorial :

tutorial here

Add in head section

<meta name="viewport" content="width=device-width, initial-scale=1.0">

CodePudding user response:

It always depends what behavior you wish. But a good practice is to use media-queries. Then set min-widthor min-height` etc. Take a look in the working example below:

.w {
  display:flex;
  background: gray;
}
.w h1 {
  font-size: 40px;
  padding: 20px;
}
img {
  width: 100%;
  height: auto;
  min-width: 200px;
}  

}
@media only screen and (max-width: 600px) {
  .w {
    background-color: lightblue;
  }
  .w h1 {
    font-size: 20;
    font-weight: bold;
    padding: 5px;
  }
}
<div >
  <div>
    <h1>Lorem Ipsum</h1>      
  </div>
  <div>
    <img src="https://via.placeholder.com/500">
  </div>
</div>

  • Related