This question already has answers here:
Centering a background image, using CSS
                                
                                    (12个答案)
                                
                        
                                5年前关闭。
            
                    
我试图将背景图像的边距设置为中心: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>

最佳答案

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

background-position: center;


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

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

09-26 23:45