您的位置:首頁技術文章
文章詳情頁

css - 為什么video不能填滿整個父級div?底部有黑邊?

瀏覽:76日期:2023-01-16 14:57:07

問題描述

代碼如下:

<!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='http://www.wxshucaidpc.com/wenda/test.mp4' type='video/mp4' /> <p>Your browser does not support the video tag.</p> </video></p></body> </html>

最終的顯示效果:css - 為什么video不能填滿整個父級div?底部有黑邊?

css - 為什么video不能填滿整個父級div?底部有黑邊?

我的疑惑是:為什么父元素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就正常了。。

標簽: CSS
相關文章:
国产综合久久一区二区三区