Show content in desktop version and hide it in mobile version. And vice versa

Asked

Viewed 1,959 times

0

I have a form with two different features, one for mobile and the other for desktop. I don’t know how to set up one to be displayed and another hidden depending on whether the site is on desktop or mobile.

Reading some answers here from the forum I tried the following:

<!-- aparecer no desktop -->
<div class="mobile-hide">
  ------------------------------------------
  <div style="position: fixed; bottom: 0; width:1170px; text-align: center;">
    <?php get_template_part('inc_booking'); ?>
  </div>
  código do 1° formulário, sem necessidade de alteração 
  ------------------------------------------
</div>
<!-- /aparecer no desktop -->

<!-- aparecer no mobile -->
<div class="mobile">
  <div class="desktop-hide">
  ------------------------------------------
    <?php get_template_part('inc_booking'); ?>
  </div>
  código do 2° formulário, sem necessidade de alteração 
  ------------------------------------------
</div>
<!-- /aparecer no mobile -->

But both versions are being presented on both desktop and mobile.

  • Can’t use CSS Media Queries?

  • edtei the answer to meet your request in the comment. Make a test and return the result.

  • If you are using Bootstrap see in that simple answer.

2 answers

3

code snippet extracted from bootstrap library:

@media (max-width: 767px) {
    .hidden-xs {
        display: none!important
    }
}
@media (min-width: 768px)and (max-width: 991px) {
    .hidden-sm {
        display: none!important
    }
}
@media (min-width: 992px)and (max-width: 1199px) {
    .hidden-md {
        display: none!important
    }
}
@media (min-width: 1200px) {
    .hidden-lg {
        display: none!important
    }
}

Edit: I put the exact width Hidden-Xs: hide for mobile phones (<768px);

Hidden-Sm: hidden for tablets ( 768px);

Hidden-Md: hide for desktops (>= 992px and < 1200px)

Hidden-lg: hide for desktops (>= 1200px)

information also extracted from bootstrap documentation.

See more in https://getbootstrap.com/css/

  • Cool Diego, where can I include the form code in the content you submitted? Mobile Code: <? php get_template_part('inc_booking'); ? > Desktop Code: <div style="position: Fixed; bottom: 0; width:1170px; text-align: center;"> <? php get_template_part('inc_booking'); ? > </div>

  • In any css block or sheet. I hope I helped, hugs

0

Since your page is PHP....

<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Qualquer dispositivo móvel (telefones ou tablets).
if ( $detect->isMobile() ) {
    echo ("<div class=\"mobile\"><div class=\"desktop-hide\">".get_template_part('inc_booking')."</div></div>");
}else{
    echo ("<div class=\"mobile-hide\"><div style=\"position: fixed; bottom: 0; width:1170px; text-align: center;\">".get_template_part('inc_booking')."</div></div>");
}
?>

Mobile_detect.php

  • Thanks Leo, where can I include the form code in the content you submitted? Mobile Code: <?php get_template_part('inc_booking'); ? > Desktop Code: <div style="position: Fixed; bottom: 0; width:1170px; text-align: center;"> <?php get_template_part('inc_booking'); ? > </div>

  • This get_template_part('inc_booking') is a function right, so with javascript it will not scroll. I will do with edit the answer with pure PHP.

Browser other questions tagged

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