css - 为什么video不能填满整个父级div?底部有黑边?
PHP中文网
PHP中文网 2017-04-17 14:58:35
0
3
851

代码如下:

<!DOCTYPE html>  
<html>  
<head>  
<title>Demo</title>  
<style>
.videoContainer {
    width: 70%;
    height: auto;
    background: #000;
}
</style>
</head>  
  
<body>   
<p class="videoContainer" >
    <video id="myVideo" controls preload="auto" width="100%" height="100%" >
      <source src="test.mp4" type="video/mp4" />
      <p>Your browser does not support the video tag.</p>
    </video>
</p>
</body>  
</html>  

最终的显示效果:

我的疑惑是:为什么父元素p会比video高出几个像素,从而导致底部有黑边?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
PHPzhong

In addition, it seems that this black border is due to the background attribute in the parent element style, specifically the background-color attribute. As for the cause, To be honest, I don’t know...

Currently it is speculated that the reason may be related to the default display of video being inline.

So the solution should be:

  1. plus font-size: 0;;

  2. Remove the background/background-color attribute;

  3. adds <video> style to display: block;.

阿神

Because your parent element videoContainer has no height, when <video> uses the contorl attribute, a black border will appear.
**Solution:
1. Delete the contorl attribute
2. Give the parent element height, or use padding to spread it, etc. **

阿神

Actually, this is an HTML bug, and it will be normal if the font size of the parent is set to 0. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template