前端不让图片浮在视频上面,让他出现在另一个div块级元素里
时间: 2024-12-04 16:28:22 浏览: 24
在前端开发中,如果你想要让图片位于视频下方的另一个`<div>`元素内,而不是覆盖在视频上,你可以通过CSS布局来控制。这里有一些建议:
1. **浮动(Float)**:给包含图片和视频的容器设置`display: flex`,然后对图片应用`float: bottom`属性,这样图片会自然地向下移动,不会影响到上方的视频。
```html
<div class="container">
<video></video>
<img src="..." alt="...">
</div>
<style>
.container {
display: flex;
flex-direction: column; /* 或者 justify-content: space-between; 如果你想保持一定间距 */
}
img {
float: bottom;
clear: both; /* 确保图片不会和其他浮动内容重叠 */
}
</style>
```
2. **绝对定位(Positioning)**:将图片设置为`position: absolute`,并设置`bottom: 0`,使其相对于最近的非静态定位祖先元素定位,这样图片会在视频下方显示。
```html
<div class="parent">
<video></video>
<div class="image-container">
<img src="..." alt="...">
</div>
</div>
<style>
.parent {
position: relative;
}
.image-container {
position: relative;
padding-bottom: 56%; /* 视频高度占容器的高度,假设是16:9的比例 */
}
img {
position: absolute;
bottom: 0;
width: 100%;
height: auto;
}
</style>
```
阅读全文
相关推荐


















