试图将我的背景图像放在 Div 元素中,但它在重复

问题描述 投票:0回答:1

我试图将我的背景图片放在一个 div 元素中,但是当我添加 div 时它会垂直重复,即使使用 background-repeat: no-repeat;我的检查工具说我溢出了。我该如何阻止这种情况发生?

<head>
<style>
    body {
        background-color: rgb(21, 32, 43); 
        
    } 
           
    div {
        
        background-image: url("chewy.jpg");
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center center;

        height: 200px;
        
    }
           
    </style>

    
</head>

<body>
 <div>
    stuff here
</div>

</body>

html css overflow background-image
1个回答
0
投票
Make a class

    <head>
<style>
    body {
        background-color: rgb(21, 32, 43); 
        
    } 
           
    .header-box {
        
        background-image: url("chewy.jpg");
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center center;

        height: 200px;
        
    }
           
    </style>

    
</head>

<body>
 <div class="header-box">
    stuff here
</div>

</body>

也许上课

.header-box { 背景图像:url(“有嚼劲的.jpg”); 背景大小:包含; 背景重复:不重复; 背景位置:中心中心; 高度:200px; }
© www.soinside.com 2019 - 2024. All rights reserved.