css - 为什么video不能填满整个父级div?底部有黑边?
问题描述
代码如下:
<!DOCTYPE html> <html> <head> <title>Demo</title> <style>.videoContainer { width: 70%; height: auto; background: #000;}</style></head> <body> <p > <video controls preload='auto' > <source src='https://www.haobala.com/wenda/test.mp4' type='video/mp4' /> <p>Your browser does not support the video tag.</p> </video></p></body> </html>
最终的显示效果:

我的疑惑是:为什么父元素p会比video高出几个像素,从而导致底部有黑边?
问题解答
回答1:补充下,貌似这个黑边是因为父元素样式里有了background属性,具体来说是background-color这个属性,至于成因是什么,实话讲我也不知道……
目前猜测原因可能是和video默认的display是inline有关系。
所以解决方案应该是:
加上font-size: 0;;
去掉background/background-color属性;
给<video>加上display: block;样式。
回答2:因为你的父元素videoContainer没有高度,当<video>使用了contorl属性的时候,就会出现一个黑边。**解决方法:1、删掉contorl属性 2、给父元素高度,或者用padding撑开等**
回答3:其实这是一个html的bug,父级的font size设为0就正常了。。
相关文章:
1. docker不显示端口映射呢?2. dockerfile - 为什么docker容器启动不了?3. html5 - 如何让H5页面在手机浏览器里和微信全屏显示4. angular.js - angularjs的自定义过滤器如何给文字加颜色?5. docker镜像push报错6. 为什么我ping不通我的docker容器呢???7. docker 17.03 怎么配置 registry mirror ?8. angular.js使用$resource服务把数据存入mongodb的问题。9. 关于docker下的nginx压力测试10. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””

网公网安备