<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="smartphone">
<div class="content">
<iframe src="https://wpcoder.co.uk/links/mixkit-man-holding-neon-light-1238-large.mp4" style="width:100%;border:none;height:100%" />
</div>
</div>
</body>
</html>
CSS:
/* The device with borders */
.smartphone {
position: relative;
width: 360px;
height: 640px;
margin: auto;
border: 16px black solid;
border-top-width: 60px;
border-bottom-width: 60px;
border-radius: 36px;
}
/* The horizontal line on the top of the device */
.smartphone:before {
content: '';
display: block;
width: 60px;
height: 5px;
position: absolute;
top: -30px;
left: 50%;
transform: translate(-50%, -50%);
background: #333;
border-radius: 10px;
}
/* The circle on the bottom of the device */
.smartphone:after {
content: '';
display: block;
width: 35px;
height: 35px;
position: absolute;
left: 50%;
bottom: -65px;
transform: translate(-50%, -50%);
background: #333;
border-radius: 50%;
}
/* The screen (or content) of the device */
.smartphone .content {
width: 360px;
height: 640px;
background: white;
}
您有两个选项:
video
和source
标签将其嵌入网页。 HTML
:<video>
<source src="video.mp4" type="video/mp4" />
<!-- src and type are an example -->
</video>
一旦您将视频嵌入网页,您需要在网页上嵌入一个手机图像。您可能有想使用的手机图像,或者您可以从最大的三个版权免费图像网站之一导入:
一旦您将视频和图片嵌入网页,就开始编辑HTML和CSS:
z-index
值设置为比图片高,以使其在图片之上显示。 CSS
:/* For Video: */
/* Use this if you hosted the video yourself: */
video {
z-index: 999; /* any value greater than img's */
}
/* Use this if you used a host: */
iframe {
z-index: 999; /* any value greater than img's */
}
/* For Image: */
img {
z-index: -999; /* any value smaller than video's */
}
position
设置为absolute
,以便它不会与图像同时出现,并且添加像素值到left
、right
、top
和/或bottom
,以使它恰好位于手机图像上方。 CSS
:/* Use this if you hosted yourself: */
video {
position: relative;
top: 10px; /* example */
left: 5px; /* example */
}
/* Use this if you use a host: */
iframe {
position: relative;
top: 10px; /* example */
left: 5px; /* example */
}
高度
和宽度
,直到它完美地适配手机屏幕。 HTML
:<!-- Use this if you hosted the video yourself: -->
<video>
<source src="video.mp4" type="video/mp4" width="100px" height="500px" />
<!-- src, type, width and height are an example -->
</video>
<!-- If you used a host, edit width and height in embed tag(s) they provided: -->
<iframe width="100px" height="500px"></iframe>
<!-- Width and height are an example -->
我成功地做到了这一点,通过将来自YouTube的音乐视频放置到来自Unsplash的手机图像上:JSBin 或从此处运行代码片段:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Video in Phone</title>
<style>
iframe {
position: absolute;
z-index: 9999;
left: 115px;
top: 133px;
}
img {
z-index: -9999;
}
</style>
</head>
<body>
<img src="https://images.unsplash.com/photo-1505156868547-9b49f4df4e04?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80" height="500px" />
<iframe width="140px" height="250px" src="https://www.youtube.com/embed/uYg4cUyJ7v0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</body>
</html>
position: relative
。 - inspirednz
:before
、:after
。 - Aman