在来练习一个全屏视频背景的项目:
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="banner">
<video autoplay muted loop>
<source src="1.mp4" type="video/mp4">
</video>
<div class="content">
<h1>风景介绍:</h1>
<p>张家界,原称“大庸”,湖南省辖地级市,位于湖南西北部,澧水中上游,属武陵山区腹地,总面积9516平方千米,辖2个市辖区(永定区、武陵源区)、2个县(慈利县、桑植县);因旅游建市,是中国最重要的旅游城市之一,是湘鄂渝黔革命根据地的发源地和中心区域。</p>
</div>
</div>
</body>
</html>
接下来是CSS代码:
body
{
margin: 0;
padding: 0;
font-family: 'Poppins',sans-serif;
height: 1000px;
}
.banner
{
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
}
.banner video
{
position: absolute;
top: 0;
left: 0;
object-fit: cover;
width: 100%;
height: 100%;
pointer-events: none;
}
.banner .content
{
position: relative;
z-index: 1;
max-width: 1000px;
margin: 0 auto;
text-align: center;
}
.banner .content h1
{
margin: 0;
padding: 0;
font-size: 4.5em;
text-transform: uppercase;
color: #fff;
}
.banner .content p
{
font-size: 1.5em;
color: #fff;
}