Image with vertical scroll and height 100%

3

I have the following structure:

<div class="bg">
    <img src="view/img/planta-supermercado.png" id="bg">
    <div class="bg-scroll" id="bg-scroll">
        <img src="view/img/planta-supermercado.png" id="bg-mobile">
    </div>
</div>

When opening the page by mobile, it loads the div with the id bg-scroll

What I need is for the image to be 100% in height and proportional in width (the width is greater than the height) ... and for that to happen I should create a horizontal scroll only in the image (or div bg-scroll ) so that the user can see the whole image.

Thank you!

    
asked by anonymous 28.05.2018 / 16:05

3 answers

2

Dude, I did not quite understand what you want. But I think it's something like that. But if it's not exactly that, it's just a touch.

OBS: Here I used small values to simulate that you are on a mobile phone. What I did was put a overflow:auto in the parent div basically.

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
.bg {
    width: 20vw;
    height: 100vh;
    overflow-y: hidden;
    overflow-x: auto;
    background-color: #f00;
}
    
.bg img {
    display:block;
    min-height: 100vh;
    width: auto;
}
<div class="bg">
    <!-- <img src="view/img/planta-supermercado.png" id="bg"> -->
    <div class="bg-scroll" id="bg-scroll">
        <img src="http://placecage.com/300/100"id="bg-mobile">
    </div>
</div>
    
28.05.2018 / 16:32
1
.bg {
   width: 100%;
   height: 100vh;
}

If you are using viewport it makes your work easier. The vh unit basically checks "how many% of the screen" your element will occupy

    
28.05.2018 / 17:06
0

First the css for your image:

#bg-mobile{
  position: relative;
  width: 100%;
  margin:0;
  padding:0;
}

Now the div:

#bg{
  position: relative;

}

With this css your div will be in bg

    
28.05.2018 / 16:11