Responsive on PC but not on tablet or mobile phone

Asked

Viewed 32 times

2

inserir a descrição da imagem aqui

background-image: url("../assetsimages/book.jpg");
background-size: 100% auto;
background-repeat: no-repeat;
max-width:auto;
height: auto;

As you can see on tablet and mobile phone is not responsive and do not understand why.

1 answer

1


For the background to be 100% height you also need to set the height in HTML. I also suggest using the background-size as cover. Link to the documentation: https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

In this example below you can see that the image always gets to 100% height occupies the width of the device without losing the "ratio"

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
body {
    background-image: url(https://www.digitaltrends.com/wp-content/uploads/2012/04/open-book.jpg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

Screenshot of the result in Chrome Devtools simulating the background on mobile device.

inserir a descrição da imagem aqui

  • worked.thanks.

  • This ai is responsive background, the rest will remain non-responsive.

  • @Sveen by the code posted along with the question assumed it would be about the background. If it were to be the full page I believe I would have the rest of the code in question... Even feel free to answer as you see fit, the author can change the acceptance of the answer whenever he wants if something comes up that he thinks best served what he needed. There are questions out there with more than 10 answers.

  • I’m not taking credit for it, I thought so, but look https://answall.com/questions/286307/texto-responsivo-html

  • @Sveen may seem strange, but what he did is absolutely right! Under STOF rules it is indicated that no more than one question is asked at the same time. He asked BG a question, now one for the other things he needs. Better than asking a question with several things to answer at the same time. After a look here, there are several debates on this point https://pt.meta.stackoverflow.com/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.