Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 我如何使我的元素(img和视频)100%的高度和水平居中?_Html_Css_Position - Fatal编程技术网

Html 我如何使我的元素(img和视频)100%的高度和水平居中?

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

这是我所拥有的(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">
    <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%;
}