在移动设备上隐藏PHP中的div内容,可以通过以下几种方法实现:
@media only screen and (max-width: 768px) {
.hidden-div {
display: none;
}
}
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
document.getElementById("div-id").style.display = "none";
}
<?php
$isMobile = false;
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$mobileKeywords = array('Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'IEMobile', 'Opera Mini');
foreach ($mobileKeywords as $keyword) {
if (strpos($userAgent, $keyword) !== false) {
$isMobile = true;
break;
}
}
if (!$isMobile) {
echo '<div>Content to be hidden on mobile devices</div>';
}
?>
以上是几种常见的在移动设备上隐藏PHP中div内容的方法。根据具体需求和场景选择合适的方法进行实现。
领取专属 10元无门槛券
手把手带您无忧上云