使用 flex 作为显示,并将视频作为 child 不符合我的填充设置
Using flex as display, and having a video as child does not respect my fill setting
我想在 HTML 页面上:
- header div - 一些高度,基于其内容
- 内容div(低于header)-取header
以下剩余高度
- table (in content div) - 对其 parent (content div)
的两个维度取 100%
- 视频项目(在 table 中)- 为其 parent (td)
的两个维度取并 保留 100%
这是我的:
body { margin: 0; }
#main {
position: absolute;
left:0px;
top:0px;
display: flex;
flex-direction: column;
height: 100vh;
width: 100vw;
background:red;
}
#header {
background:yellow;
}
#content {
background:gray;
flex:1;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
video {
width: 100%;
height: 100%;
}
<html>
<body>
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
现在,问题出在视频标签上(如果你 运行 这个片段会有滚动条 - 我不想要它们)。
如果我删除视频标签,一切都会按预期进行。
但是,如果有视频标签,它会破坏 'flex' 选项:它会扩大 td,因此 table 也会变大,然后内容也会变大 - 因此启用了滚动条和页面不适合屏幕。
也许视频在加载媒体时调整了大小,那时所有 css 操作都已完成。
但是,即使在播放过程中,如何使视频的大小与其 parent (td) 的 100% 宽度和高度完全相同?
你想要这个...
body {
margin: 0;
}
#main {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
background: red;
}
#header {
background: yellow;
}
#content {
background: gray;
flex: 1;
height: 100%;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
td {
position: relative;
}
video {
position: absolute;
width: 100%;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<html>
<body>
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
你可以制作视频position:absolute
body {
margin: 0;
}
#main {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
background: red;
}
#header {
background: yellow;
}
#content {
background: gray;
flex: 1;
min-height: 0;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
td {
position: relative;
}
video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>
我想在 HTML 页面上:
- header div - 一些高度,基于其内容
- 内容div(低于header)-取header 以下剩余高度
- table (in content div) - 对其 parent (content div) 的两个维度取 100%
- 视频项目(在 table 中)- 为其 parent (td) 的两个维度取并 保留 100%
这是我的:
body { margin: 0; }
#main {
position: absolute;
left:0px;
top:0px;
display: flex;
flex-direction: column;
height: 100vh;
width: 100vw;
background:red;
}
#header {
background:yellow;
}
#content {
background:gray;
flex:1;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
video {
width: 100%;
height: 100%;
}
<html>
<body>
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
现在,问题出在视频标签上(如果你 运行 这个片段会有滚动条 - 我不想要它们)。
如果我删除视频标签,一切都会按预期进行。 但是,如果有视频标签,它会破坏 'flex' 选项:它会扩大 td,因此 table 也会变大,然后内容也会变大 - 因此启用了滚动条和页面不适合屏幕。
也许视频在加载媒体时调整了大小,那时所有 css 操作都已完成。
但是,即使在播放过程中,如何使视频的大小与其 parent (td) 的 100% 宽度和高度完全相同?
你想要这个...
body {
margin: 0;
}
#main {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
background: red;
}
#header {
background: yellow;
}
#content {
background: gray;
flex: 1;
height: 100%;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
td {
position: relative;
}
video {
position: absolute;
width: 100%;
height: 100%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<html>
<body>
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
你可以制作视频position:absolute
body {
margin: 0;
}
#main {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
background: red;
}
#header {
background: yellow;
}
#content {
background: gray;
flex: 1;
min-height: 0;
}
table {
width: 100%;
height: 100%;
background: blue;
color: white;
}
td {
position: relative;
}
video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div id="main">
<div id="header">
Header
</div>
<div id="content">
<table>
<tr>
<td>
<video controls>
<source src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4" type="video/mp4">
</video>
</td>
</tr>
</table>
</div>
</div>