html - 如何在 Wordpress 上检测基于设备的 HTML 代码?
问题描述
我没有 HTML 方面的经验,并试图在 WordPress 上为自己制作一个小型网站。
我有以下自定义代码可以在我的网站上播放视频:
<video poster="video poster link" controls="controls" width="270" height="490">
<source src="video link" type="video/mp4"></video>
视频播放器在桌面站点中完美显示。然而,当 WordPress 为平板电脑调整网站大小时,它确实延伸了很多。因此,我想在代码显示在平板电脑/移动设备上时更改其大小。
为了检测我在网上找到了以下代码,但我无法让它工作:
<?php
if ( wp_is_mobile() ) {
/* Include/display resources targeted to phones/tablets here */
} else {
/* Include/display resources targeted to laptops/desktops here */
}
?>
谢谢你。
解决方案
如果您在 wordpress 站点中没有对代码的编辑权限,则可以添加类似fitvids的插件。如果您确实具有编辑权限,则可以添加媒体查询以检查设备宽度是否像这样
@media screen and (max-width: 768px) {
video {
max-width: 75%;
height:auto;
} // iPad
@media screen and (max-width: 480px) {
video {
max-width: 45%;
height:auto;
} //Phone
根据需要调整宽度..
希望这可以帮助
推荐阅读
- android - 数据绑定重定向到 xml 在 android studio 3.1.2 中不起作用
- python - OpenCV video not getting saved
- scala - 如何在另一个内部命令(不是外部命令)的 sbt 中获取返回码?
- variables - “...不是内部或外部命令、可运行程序或批处理文件。”
- c++ - OpenCV predict() 与 detectMultiScale()
- android - 拍照后如何不预览照片?
- ionic-framework - Ionic 2 状态栏颜色文本
- xml - 如何根据属性获取多个代码的计数
- python - 为什么 pandas 的 apply 方法没有一个 axis=None 选项来将函数应用于整个数据框?
- java - 如何使用 Apache Camel Netty4 在异步模式下通过已建立的 TCP 连接发回响应?