用css居中背景图像

时间:2014-09-25 20:25:05

标签: html css background center

我正在尝试使用保证金为中心背景图片:0自动,但无效,我已经放display: block;

:root {
    background-color: black;
    margin: 0 auto;
}
header  {
    background-image: url('../imagens/fundoheader.png');
    background-repeat: no-repeat;
    height: 100%;
    display: block;
    margin: 0 auto;
}
ul.menu {
    text-align: center;
}
.menu li {
    display: inline;
    margin-left: 10px;
    color: #f8841c;
}
li img {
    width: 171px;
    height: 52px;
    position: relative;
    top: 10px;
}
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>My Site</title>
        <link rel="stylesheet" type="text/css" href="css/reset.css">
        <link rel="stylesheet" type="text/css" href="css/stylesheet.css">
        <script type="text/javascript"></script>
    </head>
    <body>
        <header>
                <ul class="menu">
                    <li><img src="imagens/logo.png"></li>
                    <li>O QUE É?</li>
                    <li>QUERO PARTICIPAR</li>
                    <li>COMO CHEGAR?</li>
                    <li>PROGRAMAÇÃO SEMANAL</li>
                    <li>EVENTOS</li>
                    <li>RESERVAS</li>
                </ul>
        </header>
        <section>




        </section>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找background-position属性

background-position: center;

您还可以将背景属性组合成一行,如下所示:

background: url('.../imagens/fundoheader.png') no-repeat center;