自定义CSS并引入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*哔哩哔哩视频适配*/
.video-bilibili {
position: relative;
width: 100%;
height: 0;
padding-bottom: 65%;
margin: 3% auto;
text-align: center;
}
.video-bilibili iframe {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}

.video-youtube {
position: relative;
padding-bottom: 56.25%;
height: 0;
margin: 3% auto;
}
.video-youtube iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

用法示例

1
2
3
4
5
6
7
8
9
10
11
12
<div class="video-bilibili">
<iframe
src="https://player.bilibili.com/player.html?aid=412679216&&page=1&as_wide=1&high_quality=1&danmaku=0"
scrolling="no"
border="0"
frameborder="no"
framespacing="0"
high_quality="1"
danmaku="1"
allowfullscreen="true"
></iframe>
</div>
1
2
3
<div class="video-youtube">
<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/76_6dy-lBlA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

效果展示

电脑端展示手机端展示
bilibili电脑端bilibili手机端
youtube电脑端youtube手机端