douchun5976 2017-08-04 18:42
浏览 50
已采纳

对于响应式设计,如何为移动用户添加不同的header.php文件?

I want to change my header.php file for mobile devices. I've tried this javascript solution but it doesn't write the php file. How can I fix this?

<script language=javascript>
if (screen.width >= 720 ) 
     $('#header').load('header.php');
else (
     $('#header').load('header-mobile.php');
)
</script>
<div id="header"></div>

Thanks

  • 写回答

1条回答 默认 最新

  • duanbarong4321 2017-08-04 18:52
    关注

    Why do you want to import different files? You could use media queries with css and add a class to each type of header like this:

    <div class="mobile-header">
    </div>
    <div class="header">
    </div>
    

    And in CSS you just hide it/show it with media queries:

    .header-mobile { 
        display: none;
    }
    @media (max-width: 600px) {
        .header {
            display: none;
        }
        .header-mobile {
            display: block;
        }
    }
    

    This means that your .header-mobile div is going to be hidden, unless your window size is 600px or less, in that case, your .header is going to be hidden.

    Hope it helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)