media querie does not work

Asked

Viewed 389 times

1

Hi, I’m trying to get the background of a Ction to have a color on mobile and a desktop image but it doesn’t work. I’ll send you the code and print it out.

Apparently you seem to be right, but it doesn’t work at all. Could you help me?

mobile

desktop

@media (min-width: 1001px) {
#slice-mobile {

    background-image: url(assets/img/backgrounds/notebook2.jpg);
    background-position: bottom;
    background-position-y: 12%;
    }
}

@media (max-width: 1000px) {
    #slice-mobile { 

    background-color: #009976 !important 

    }
}
<section class="slice slice-xl slice1 slicexl1" id="slice-mobile" >
            <div class="container">
                <div class="row row-grid align-items-center">

                <div class="col-lg-6 agenda1">
                        <div class="pt-lg-lg pb-lg-sm text-center text-lg-left">
                            <h2 class="h2 text-white mb-2"><span style="border-bottom: 3px solid #5E00DE;">Agenda</span> médica completa</h2>
                            <p class="lead text-white lh-180">Utilize o Módulo de Agenda para fazer uma gestão completa de todos os seus agendamentos, incluindo atendimentos de ambulatório como consultas e retornos, ou mesmo procedimentos ou atendimentos específicos.</p>
                            <!-- <div class="countdown h2 text-white" data-countdown-date="12/01/2018" data-countdown-label="hide"></div> -->

                <div class="col-lg-12">
                    <ul class="list-unstyled">
                        <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Visualização da agenda por dia, semana ou mês.
                        </li>
                        <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Agendamento por profissional, procedimento e local.
                        </li>
                        <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Confirmação de consultas e retornos e alertas de compromissos.
                        </li>
                    </ul>
                </div>

                            <a href="https://localhost/landing_agenda/contato.php" id="iconeView2" class="btn btn-primary btn-circle btn-translate--hover mt-4"> <i class="fas fa-arrow-right arrow"></i> Fale com nossos consultores</a>
                        </div>
                    </div>
                </div>
            </div>
        </section>

  • What doesn’t work on the image??

  • If I put the image as default, the color does not appear in mobile (still showing the image). And if I put color as default, the image does not appear...

  • Well, by the way, your code won’t work anyway. The breakpoints are pointing to the same measurements. Agree with me if you have a minimum width of 1000px and a maximum width of 1000px???

  • then how would it have to be done?

4 answers

1

Try to put it like this:

@media screen and (min-width: 1001px) {
#slice-mobile {

    background-image: url(assets/img/backgrounds/notebook2.jpg);
    background-position: bottom;
    background-position-y: 12%;
    }
}
  • so neither will :(

1

To leave a color on mobile, do not need to declare a max-width. Let’s just say as standard with a color. Then when it is 1001 or higher, will exchange for the image.

Something important was missing. You can’t have !important.

#slice-mobile { 
   background-color: #009976; 
}

@media screen and (min-width: 1001px) {
   #slice-mobile {
       background-image: url(assets/img/backgrounds/notebook2.jpg);
       background-position: bottom;
       background-position-y: 12%;
       background-color: transparent;
    }
}
  • doesn’t change, I tried like this too and won’t :( I don’t know what else to do

  • when I take the important thing turns everything white. neither color nor image appears

  • You can put it on Codepen to see?

  • I already solved @Diego Souza, thanks!

1

  • Yes, it doesn’t work

  • example with color works, but I need an example with background-image

  • Try putting background-image: None; before the line calling the green background color.

  • doesn’t work anyway :(

  • @Anne just put the background hitched again to the property if that’s what you need. For example background: #000 url(Assets/img/backgrounds/notebook1.jpg); And within the media query background: #FFF url(Assets/img/backgrounds/notebook2.jpg);

0


It follows a model I made based on your code.

Notice that Bootstrap 4 is mobile first then he uses min-width, which means that only when the screen had at least 1001px wide will it put the image in the background. If the screen is smaller than 1001px it will use the color of BG.

Take the example. Run tb on "Whole Page" to see that when in widths larger than 1001px the image appears in BG.

#slice-mobile { 
    background-color: #009976;
}

@media (min-width: 1001px) {
    #slice-mobile {
        background-image: url(https://placecage.com/100/100);
        background-position: bottom;
        background-position-y: 12%;
    }
}
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.bundle.min.js"></script>

    <section class="slice slice-xl slice1 slicexl1" id="slice-mobile" >
        <div class="container">
            <div class="row row-grid align-items-center">

            <div class="col-lg-6 agenda1">
                    <div class="pt-lg-lg pb-lg-sm text-center text-lg-left">
                        <h2 class="h2 text-white mb-2"><span style="border-bottom: 3px solid #5E00DE;">Agenda</span> médica completa</h2>
                        <p class="lead text-white lh-180">Utilize o Módulo de Agenda para fazer uma gestão completa de todos os seus agendamentos, incluindo atendimentos de ambulatório como consultas e retornos, ou mesmo procedimentos ou atendimentos específicos.</p>
                        <!-- <div class="countdown h2 text-white" data-countdown-date="12/01/2018" data-countdown-label="hide"></div> -->

            <div class="col-lg-12">
                <ul class="list-unstyled">
                    <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Visualização da agenda por dia, semana ou mês.
                    </li>
                    <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Agendamento por profissional, procedimento e local.
                    </li>
                    <li style="color: #fff;" class="py-2"><i class="fas fa-check" style="color: #5E00DE;"></i> Confirmação de consultas e retornos e alertas de compromissos.
                    </li>
                </ul>
            </div>

                        <a href="https://localhost/landing_agenda/contato.php" id="iconeView2" class="btn btn-primary btn-circle btn-translate--hover mt-4"> <i class="fas fa-arrow-right arrow"></i> Fale com nossos consultores</a>
                    </div>
                </div>
            </div>
        </div>
    </section>
    

  • in your example it works yes, when I replico in mine does not work. even importing the links that you put

  • @Anne in this case I suggest you put your entire CSS in your question. Edit the question and put everything you have of CSS, because it was something you did there that is interfering with this behavior.

  • does not fit the whole CSS :( I think the problem eh in the image. When I put the same image that you worked, then when I put mine does not work :(

  • @Anne try to put this property together with the image’s CSS background-size: cover see if your image will appear. If it does not appear it may be pq the image path in the directory is wrong, or the image is a . PNG for example and vc is calling a . JPG

Browser other questions tagged

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