html - 图片不在CSS中居中

标签 html css image centering

我是 html 和 css 的新手,我已经开始制作一个网站,所以我开始正确放置 Logo 和背景,现在的问题是我无法垂直将我的 Logo 图像居中。

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <title>Insert title here</title>
</head>
<body>
    <div class="bg">
        <div class="menu">          
            <div class="logo"></div>
        </div>
    </div>
</body>
</html>

CSS:

body {
    background:url(../img/bg.png) no-repeat center center fixed;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    -o-background-size: cover;
    background-size: cover; 
    z-index:1000;
}
body {
    margin:0 ;
    padding:0;
    height: 100%;
    width: 100%;
}

.menu { 
    background:url(../img/MenuBar.png) ;
    height:150px;
    width:1242px;
    position:relative;
}

.logo { 
    background:url(../img/Untitled-1.png) no-repeat center;
    width:262px;
    height:80px;
    margin:0 auto;  
}

最佳答案

这应该可以解决问题。

.menu { 
background:url(../img/MenuBar.png) ;
height:150px;
width:1242px;
position:relative;
display: table;

.logo{

     background:url(../img/Untitled-1.png) no-repeat center;
     width:262px;
     height:80px;
     margin:0 auto;
     display: table-cell;
     vertical-align: middle;

关于html - 图片不在CSS中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22467872/

相关文章:

html - 如何在规模化的同时填补空白

css - 将 DIV 放置在两个较低的 DIV 之间和上方

javascript - React Native 将图像上传到 AWS 服务器不适用于 Android

php - 我可以水平/垂直翻转图像,但我不能用 GD2 库旋转它们

javascript - JQuery 触发器不适用于生成的元素

html - 你如何覆盖 <DT> 背景颜色来模拟禁用?

css - 我无法在我的 wp 主题上将菜单上的文本居中

javascript - 意外的标识符错误

html - 在手机上隐藏按钮

javascript - 从文件上传读取 url 时图像自动旋转(当它是大图像时)?