根据屏幕大小包含php文件

时间:2017-07-12 14:55:05

标签: javascript php jquery css

我正在开发一个响应式网页设计,它有两个不同的标题菜单,即桌面标题和移动标题。[请参阅:由于菜单内容不同,我无法使其响应]。 根据屏幕分辨率调用头文件。 我的代码是:

<style type="text/css">
@media only screen and (min-width: 768px) {
    /* tablets and desktop */
    .mobile {
        display: none
    }
}

@media only screen and (max-width: 767px) {
    /* phones */
    .desktop {
        display: none
    }
}

@media only screen and (max-width: 767px) and (orientation: portrait) {
    /* portrait phones */
    .desktop {
        display: none
    }
}
</style>
<div class="mobile">
    <?php


    include_once( WWW . 'inc/layout/mobile_header.php' );

    ?>
</div>
<div class="desktop">
    <?php 
{
  include_once(WWW . 'inc/layout/desktop_header.php');
}

?>

</div>

此代码工作正常,但我注意到两个文件都已加载,文件隐藏/显示取决于屏幕大小。 我想要一个代码,其中只能加载/执行一个PHP文件,具体取决于它的屏幕大小。

1 个答案:

答案 0 :(得分:0)

你不能用CSS做这个,因为页面已经从服务器加载,然后隐藏了元素。

为什么不设计你的标题以便反应而不处理这个?