WordPress教程

WordPress 文章内嵌入B站视频自适应

阿里云

WordPress 文章内嵌入 B 站视频自适应,在 B 站上打开需要引用的视频页面,在视频播放器下方找到【分享图标】—>【选择嵌入代码】—>【复制文本内容】。

方法一

在 WorePress 文章编辑中,选择【作为 HTML 编辑】,粘贴刚才复制的 B 站嵌入代码,在其<iframe src 元素标签中增加 class 属性,如:

也想出现在这里?联系我们
创客主机
  1. <iframe class="iframe_video"src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1&danmaku=0" width="100%" height="100%" frameborder="no" scrolling="no" allowfullscreen="allowfullscreen"> </iframe>

之后在主题模板 Css 全局样式文件中加入如下代码:

  1. /*哔哩哔哩视频*/
  2. .iframe_video {
  3.     position:relative;
  4.     width:100%;
  5. }
  6. @media only screen and (max-width:767px) {
  7.     .iframe_video {
  8.     height:15em;
  9. }
  10. }
  11. @media only screen and (min-width:768px) and (max-width:991px) {
  12.     .iframe_video {
  13.     height:20em;
  14. }
  15. }
  16. @media only screen and (min-width:992px) and (max-width:1199px) {
  17.     .iframe_video {
  18.     height:30em;
  19. }
  20. }
  21. @media only screen and (min-width:1200px) {
  22.     .iframe_video {
  23.     height:40em;
  24. }
  25. }
  26. .iframe_cross {
  27.     position:relative;
  28.     width:100%;
  29.     height:0;
  30.     padding-bottom:75%
  31. }
  32. .iframe_cross iframe {
  33.     position:absolute;
  34.     width:100%;
  35.     height:100%;
  36.     left:0;
  37.     top:0
  38. }

方法二

嵌入到 WordPress 文章中的 html 代码:

  1. <div class="smartideo">
  2.  <div class="player">
  3.   <iframe src="//player.bilibili.com/player.html?aid=243829823&bvid=BV1Sv411i7KS&cid=209606589&page=1&high_quality=1&danmaku=0" width="100%" height="100%" frameborder="no" scrolling="no" allowfullscreen="allowfullscreen"> </iframe>
  4.  </div>
  5. </div>

放在 css 中的:

  1. .smartideo { z-index: 0; text-align: center; background: #CCC; line-height: 0; text-indent: 0; }
  2. .smartideo embed, .smartideo iframe { padding: 0; margin: 0; }
  3. .smartideo .player { width: 100%; height: 500px; overflow: hidden; position: relative; }
  4. .smartideo .player a.smartideo-play-link { display: block; width: 50px; height: 50px; text-decoration: none; border: 0; position: absolute; left: 50%; top: 50%; margin: -25px; }
  5. .smartideo .player a.smartideo-play-link p { display: none; }
  6. .smartideo .player .smartideo-play-button { width: 0; height: 0; border-top: 25px solid transparent; border-left: 50px solid #FFF; border-bottom: 25px solid transparent; }
  7. .smartideo .tips { background: #f2f2f2; text-align: center; max-height: 32px; line-height: 32px; font-size: 12px; }
  8. .smartideo .tips a { text-decoration: none; }
  9.  
  10. @media screen and (max-width:959px){
  11.     .smartideo .player { height: 450px; }
  12. }
  13. @media screen and (max-width:767px){
  14.     .smartideo .player { height: 400px; }
  15. }
  16. @media screen and (max-width:639px){
  17.     .smartideo .player { height: 350px; }
  18. }
  19. @media screen and (max-width:479px){
  20.     .smartideo .player { height: 250px; }
  21. }

WordPress 文章内嵌入 B 站视频自适应

已有 198 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!