Html 我如何使我的元素(img和视频)100%的高度和水平居中?
这是我所拥有的(1和2),以及我想要的(3)。 html是Html 我如何使我的元素(img和视频)100%的高度和水平居中?,html,css,position,Html,Css,Position,这是我所拥有的(1和2),以及我想要的(3)。 html是 <div> <img id="ship" src="images/shipBG1.png" alt="" /> </div> <video autoplay loop poster="images/void.jpg" id="video"> <source src="video/Video.webm" type="video/webm"> <so
<div>
<img id="ship" src="images/shipBG1.png" alt="" />
</div>
<video autoplay loop poster="images/void.jpg" id="video">
<source src="video/Video.webm" type="video/webm">
<source src="video/Video.mp4" type="video/mp4">
</video>
要使这些元素达到100%高度,必须设置其父元素的高度。。 阿卡 这不能是%,除非它的参数具有设置的高度,如
html,body{height:100%}
或精确的px
或
而不是有div
要得到(3)我要做的是给你的图像一个minwidth
,并给parrent和overflow:hidden代码>
html, body, { width: 100%; }
#video {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
background: url(images/void.jpg) center center fixed;
background-size: cover;
}
#ship {
margin:auto;
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
height: 100%;
width: 100%;
}
div {
height: (your height)
}
html, body {
height: 100%;
}