duangu4943 2012-01-09 15:43
浏览 39
已采纳

如果屏幕尺寸小于Y,则在php文件的body标签内显示X.

I need to adapt my template to mobile versions, without creating different page files for each case, or subsites. I think the easiest way to do that is to change the css files to "rearrange" some elements.

So this is what I´ve done so far:

  • I´m working with php.

  • I´ve made use of @media queries, adding inside the <head> this: <link rel="stylesheet" type="text/css" media="only screen and (max-width: 700px)" href="/css/smartphones.css" />, so it will call the smartphones.css file each time the users access the site with a small device.

  • Everything goes kinda smoothly, up until now, when I decided to adapt the dropdown menu. I´ve got a dropdown menu in pure css, that gets activated on mouse over. I use :hover to get the menu to actually drop down.

I want to replace that big dropdown menu with many items (horizontally and vertically), to a single button, that onclick will dropdown, and show just a couple of things.

In order to do that I need to adapt my php page file to hidden the entire dropdown menu and show the "mini-onclick" dropdown menu instead. And here is what I don´t know how to do it.

I need some -javascript I guess- inside my body tag (as the menu appears inside the body) to say something like:

IF the screen is less than 700px, show this XXXX code. ELSE keep going with the rest of the page.

I´m planning to hide the normal dropdown menu using css inside the smartphones.css file, but don´t know how to show the special dropdown menu instead.

Any help will be greatly appreciated! THANKS!

Rosamunda

  • 写回答

1条回答 默认 最新

  • doudanma9706 2012-01-09 21:41
    关注

    You can use the User-Agent HTTP header in PHP to determine if smartphone-relevant code should be generated instead of normal code.

    You could also get screen properties via the screen object, and if it's a smartphone, attach the dropdown state to the onclick event and if not to the onmouseover event.

    That's pretty simple. You just change your CSS from someclass:hover to someclass.hoverstate and when the dropdown needs to be triggered, you add the hoverstate class to the target element.

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

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c