gpt4 book ai didi

html - 为什么我的视频和图像在页面顶部相互堆叠

转载 作者:行者123 更新时间:2023-11-28 14:15:20 24 4
gpt4 key购买 nike

我在我的网站上添加了一张图片,但不是另起一行并放置在我的视频下方,而是将其放置在我的视频之上,位于页面的最顶部,位于居中的黑色渐变背景之下文本。我该如何解决这个问题,以便我可以将图像放在新的一行而不是重叠在视频上?

body
{
margin: 0;
padding: 0;
background-color: rgb(244,212,188) ;
font-family: 'IntroDemo-BlackCapsInline';
}

@font-face
{
font-family: 'IntroDemo-BlackCapsInline';
src: url(IntroDemo-BlackCapsInline.otf);

}

.nav
{
position: absolute;
z-index: 2000;
color: black;
text-align: center;
padding: 20px 0 20px 0;
font-size: 19px;
width: 100%;

}
/* Padding will create space
between the words and the edges of the box*/
.nav > li
{
display: inline-block;
padding: 0 25px 0 25px; /* top left bottom right*/
/* This property will put all the elements
in the same horizontal line*/

}
.nav > li > a
{
text-decoration: none;
color: #ee0000 ;

}

.nav > li > a:hover
{
/* color: rgb(116, 181, 255);*/
background-color: rgba(255, 255, 255, 0.8);
padding: 20px 20px 20px 20px;
}

.ban
{

background-color: #f0ebe2 ;
}
#left
{
text-align: left;
display: inline-block;
color: #ee0000 ;
width: 400px;
text-align: center;
font-size: 25px;

}

#right
{
display:inline-block;
float: right;
color: #ee0000 ;
width: 400px;
text-align: center;
font-size: 20px;

}

.bg-wrap .video-ele .content
{
margin: 0;
padding: 0;
}
.bg-wrap
{
position: fixed;
z-index: -1000;
width: 100%;
height: 100%;
overflow: hidden;
top: 0;
left: 0;
}

.video-ele
{
position: absolute;
top: 0;
left: 0;
min-height: 100%;
min-width: 100%;


}

.content
{
position: absolute;
width:100%;
min-height: 100%;
z-index: 1000;
background-color: rgba(0,0,0,0.5);

}

.content h1
{
text-align: center;
font-size: 65px;
text-transform:uppercase;
font-weight: 300;
padding-top: 15%;
margin-bottom: 10px;
color: white;
}

.content p
{
text-align: center;
font-size: 20px;
letter-spacing: 3px;
color: white
}

#pic
{

}
<!DOCTYPE html>
<html lang = "en" >

<head>
<link href= "Basic_Style.css" rel = "stylesheet" type ="text/css">
<meta charset = "UTF-8">
<title> Basic Site</title>
</head>
<body>
<div class = "ban">
<h3 id = "left">Bubble</h3>
<h4 id = "right">Contact Us: 111-444-7887</h4>
</div>
<header>

<nav>
<ul class = "nav">
<li><a href = "#">Home</a></li>
<li><a href = "#">About</a></li>
<li><a href = "#">Contact</a></li>
<li><a href = "#">Inventory</a></li>
<li><a href = "#">Policy</a></li>
</ul>

</nav>
<div class = "bg-wrap">
<video id = "video-ele" preload = "auto" autoplay = "true" loop= "loop" muted="muted">
<source src = "coffe.mp4" type = "video/mp4">
Video not supported
</video>
</div>
<div class = "content">
<h1>This is my intro video</h1>
<p>I hope you like it</p>

</div>

<div>

<img id = "pic" src = "new_1.jpg" alt="picture">
</div>
</header>

</div>


</body>
</html>

最佳答案

设置 position:absolute 基本上会导致元素“悬停”在其他元素的上方或下方。为了确保其他元素不重叠,您需要这样的东西:

.absolute-element {
position: absolute;
top: 0; left: 0;
width: 200px;
height: 200px;
}

.normal-element {
margin-top: 205px;
width: 200px;
height: 200px;
}

您需要将除视频以外的所有内容都包裹在标签中,并将其设置在视频下方,或者一次为一个元素腾出空间。您还可以使用绝对定位视频的确切大小的 div:

.absolute-element {
position: absolute;
top: 0; left: 0;
width: 200px;
height: 200px;
}

.div-overlapping-video {
width: 200px;
height: 200px;
}

.normal-element {
width: 200px;
height: 200px;
}

对于最后一个选项,您可能需要使用负边距或正边距来确保 div 正好位于视频内。

关于html - 为什么我的视频和图像在页面顶部相互堆叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55978972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com