【发布时间】:2025-12-03 11:30:01
【问题描述】:
【问题讨论】:
-
在背景或伪中使用手机边框图片
:before,:after
标签: javascript html css html5-video
【问题讨论】:
:before,:after
标签: javascript html css html5-video
你有两个选择:
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 */
}
height 和width,直到它完全适合手机屏幕。 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 或者从这里运行代码 sn-p:
<!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。
希望这对某人有所帮助:
HTML:
<!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://tapcart.com/vids/fashionnova_video.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;
}
【讨论】: