我想在div
中添加全宽度的视频标签,id是使用javascript的视频。你能帮我吗?
let video = document.createElement("video")
video.width = 320;
video.height = 180;
video.style.background = "black"
document.getElementById("video").append(video);
<html>
<body style="background: lightgrey">
<div class="container">
<div id="video"></div>
</div>
</body>
</html>
<video width="100%" height="auto" controls>
<source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
message if vodeo does not show
</video>
with
#video {
width: 100%;
height: auto;
}
在你的css中,视频将始终使用其父元素的全部可用宽度,在本例中是"container"
我认为这是一个评论,但我不能评论,所以我把它作为一个答案。
let video = document.createElement("video")
video.width = 320;
video.height = 180;
video.style.background = "black"
document.getElementById("video").append(video);
#video video {
width: 100% !important;
}
<html>
<body style="background: lightgrey">
<div class="container">
<div id="video"></div>
</div>
</body>
</html>
如下:
<script>
var myVideo = document.getElementById("video");
myVideo.innerHTML()='
<video id="video" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>';
</script>
但是脚本需要在<div id="video">
标签创建之后。