Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.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
Css 如何在div中居中图像(屏幕高度%)_Css_Html_Height_Percentage - Fatal编程技术网

Css 如何在div中居中图像(屏幕高度%)

Css 如何在div中居中图像(屏幕高度%),css,html,height,percentage,Css,Html,Height,Percentage,我的网站有一个标题,占据了20%的屏幕。我想要一个图像(90%的页眉高度)在页眉的正中央。我可以水平居中图像,但不能垂直居中。代码如下: <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Website</title> <link rel="stylesheet" href="stylingpercen

我的网站有一个标题,占据了20%的屏幕。我想要一个图像(90%的页眉高度)在页眉的正中央。我可以水平居中图像,但不能垂直居中。代码如下:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Website</title>
    <link rel="stylesheet" href="stylingpercent.css" />
</head>

<body>

    <header>
        <div class="logoheader" >
            <img class="mainlogo" src="logo.png" alt="logo">
        </div>

    </header>



</body>

</html>
添加以下内容:

line-height: 20vh;

.logoheader

图像的高度是静态的吗?否,它取决于标题高度,您可以参考垂直对齐。这里有一个演示:现在它可以工作了!非常感谢你!
line-height: 20vh;