我想在我的顶部包装器上使用视频,而不是使用照片作为背景img。我是html5和css3的初学者,所以如果我的问题不清楚,我真的很抱歉。
如果有人可以教我如何编写代码来添加背景视频而不是全屏类型背景,那将非常感激,仅适用于我的顶级包装。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TakashiKaida</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
</head>
<body>
<header>
<div class="container">
<div class="header-left">
</div>
<div class="header-right">
<a href="file:///Users/takashikaida/Documents/Takashi%20Kaida%20Personal/index.html">Home</a>
<a href="#" class="about">About</a>
<a href="#" class="blog">Blog</a>
<a href="#" class="cv">CV</a>
</div>
</div>
</header>
<div class="top-wrapper">
<div class="container">
<h1>HELLO, IT'S ME.</h1>
<h1>I AM TAKASHI</h1>
<p><br><br>Marketing Analyst/Assistant</p>
<p>Co-Founder and CEO of <a href="file:///Users/takashikaida/Desktop/Flow%20Full%20Screen%20Type/index.html" target="_blank"> <strong>FLOW</strong></a></p>
</div>
</div>
</div>
CSS:
body {
margin: 0;
font-family: "Hiragino Kaku Gothic ProN";
}
a {
text-decoration: none;
}
.container {
width: 1170px;
padding: 0 15px;
margin: 0 auto;
}
.top-wrapper {
padding: 180px 0 100px 0;
background-image: url(background-photo.jpg);
background-size: cover;
color: white;
text-align: center;
opacity: 0.8;
}
.top-wrapper h1 {
font-size: 75px;
letter-spacing: 5px;
padding-top: 5px;
}
.top-wrapper p {
font-size: 25px;
}
header {
height: 65px;
width: 100%;
background-color: rgba(34, 49, 52, 0.9);
position: fixed;
top: 0;
z-index: 10;
}
.logo {
width: 124px;
margin-top: 20px;
}
.header-left {
float: left;
}
.header-right {
float: right;
transition: all 0.5s;
}
.header-right a {
line-height: 65px;
padding: 0 25px;
color: white;
display: block;
float: right;
}
.about-me {
height: 500px;
padding-bottom: 80px;
background-color: #f7f7f7;
text-align: center;
}
.heading {
padding-top: 60px;
padding-bottom: 30px;
color: #5f5d60;
}
.heading h1 {
font-weight: normal;
}
.profile {
float: left;
width: 25%;
}
.lesson-icon {
position: relative;
}
.lesson-icon p {
position: absolute;
top: 90px;
width: 100%;
color: white;
}
.txt-contents {
width: 80%;
display: inline-block;
margin-top: 20px;
font-size: 12px;
color: #b3aeb5;
}
.heading h3 {
font-weight: normal;
}
.message-wrapper {
border-bottom: 1px solid #eee;
padding-bottom: 80px;
text-align: center;
}
.message {
padding: 15px 40px;
background-color: #5dca88;
cursor: pointer;
box-shadow: 0 7px #1a7940;
}
.message:active {
position: relative;
top: 7px;
box-shadow: none;
}
.bottom-btn-list {
text-align: center;
}
footer p {
color: #b3aeb5;
font-size: 12px;
margin: auto;
width: 50%;
padding: 30px;
text-align: center;
}
footer {
padding-top: 30px;
text-align: center;
background-color: #333631
}
.my-skyblue {
color: skyblue;
}
.my-white {
color: white;
}
这很简单。您可以从以下方法添加视频。
<video src="/myvideo.mp4"></video>
<video src="video.mp4" controls> <object data="player.swf" type="application/x-shockwave-flash"> <param value="player.swf" name="movie"/> ...etc... </object> </video>
在顶部包装器中添加视频元素,请参阅下面的样式
.top-wrapper {
position:relative;
background:rgba(255,0,0,0.1);
}
.top-wrapper .video {
position:absolute;
width:100%;
height:100%;
background:green;
z-index:-1;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TakashiKaida</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
</head>
<body>
<header>
<div class="container">
<div class="header-left">
</div>
<div class="header-right">
<a href="file:///Users/takashikaida/Documents/Takashi%20Kaida%20Personal/index.html">Home</a>
<a href="#" class="about">About</a>
<a href="#" class="blog">Blog</a>
<a href="#" class="cv">CV</a>
</div>
</div>
</header>
<div class="top-wrapper">
<video class="video" src="https://upload.wikimedia.org/wikipedia/commons/f/fc/Storforsen_video_12.webm" autoplay></video>
<div class="container">
<h1>HELLO, IT'S ME.</h1>
<h1>I AM TAKASHI</h1>
<p><br><br>Marketing Analyst/Assistant</p>
<p>Co-Founder and CEO of <a href="file:///Users/takashikaida/Desktop/Flow%20Full%20Screen%20Type/index.html" target="_blank"> <strong>FLOW</strong></a></p>
</div>
</div>
</div>
这是一个想法,你可以尝试:
video
标签导入视频文件video
的风格,如:video {
min-width: 100%; min-height: 100%;
width: auto; height: auto; z-index: -100;
}