gpt4 book ai didi

html - 如何在 Wordpress 上检测基于设备的 HTML 代码?

转载 作者:行者123 更新时间:2023-11-28 14:11:15 25 4
gpt4 key购买 nike

我没有 HTML 方面的经验,并试图在 WordPress 上为自己制作一个小网站。

我有以下自定义代码可以在我的网站上播放视频:

<video poster="video poster link" controls="controls" width="270" height="490">
<source src="video link" type="video/mp4"></video>

视频播放器在桌面站点中完美显示。但是,当 WordPress 为平板电脑调整网站大小时,它确实会拉伸(stretch)很多。因此,我想在代码中更改在平板电脑/移动设备上显示时的大小。

为了检测,我在网上找到了以下代码,但我无法让它工作:

<?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

根据需要调整宽度..

希望对你有帮助

关于html - 如何在 Wordpress 上检测基于设备的 HTML 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56417949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com