在移动设备上隐藏HTML

时间:2020-04-27 12:56:18

标签: php html

我想出了如何在移动设备上显示元素

<?php if(detectMobile()) { ?>
htmlcode
<?php } ?>

但是,我正尝试相反的做法,并希望在移动设备上隐藏元素。 我知道CSS可以做到这一点,但是在这种情况下,我不想使用display:none选项,因为它使用与某些其他元素相同的CSS,应该隐藏在移动设备上。在这种情况下,我也不想要创建唯一的CSS。

1 个答案:

答案 0 :(得分:1)

只需通过添加!将您的if yes(是)更改为if(如果不是)。 (不是运算符)

您的代码变为:

<?php 

if( !detectMobile() ) 
{ 
    ?>
    htmlcode
    <?
} 
?>

或使用if else结构。您的代码将变为:

<?php 

if( detectMobile() ) 
{ 
    // future code in case we must do something for mobile.
    ?>

    <?
} 
else 
{
    // if not mobile, then this code is being used.
    ?>
        htmlcode
    <?
}
?>