简体   繁体   English

CSS:图像仅显示半高,并显示多次宽度?

[英]CSS: Image only showing half height, and showing multiple times width wise?

It seems that my code is repeating the image width ways, and only showing half of it height wise?似乎我的代码正在重复图像宽度的方式,并且只在高度上显示一半?

 html, body { background-color: black; } .tile.floor { background-image: url('https://i.imgur.com/7es7QMs.png'); } .tile.floor:empty::after { content: "\\200b"; visibility: hidden; }
 <div class="tile floor"></div> <script src="/assets/js/app.js"></script>

I have attached a JS fiddle with all the code I'm using.我附上了一个带有我正在使用的所有代码的 JS 小提琴。

JS fiddle JS小提琴

Try setting .tile.floor 's height to the height of the image.尝试将.tile.floor的高度设置为图像的高度。

html, body {
    background-color: black;
}

.tile.floor {
    background-image: url('https://i.imgur.com/7es7QMs.png');
    height: 40px;
}

.tile.floor:empty::after {
    content: "\200b";
    visibility: hidden;
}

As per my understanding, it does what you want.根据我的理解,它可以满足您的需求。

I'm not entirely sure what you're asking for here.我不完全确定你在这里要求什么。 But if you want the image to resize to the height of your element, use background-size: contain .但是,如果您希望图像调整到元素的高度,请使用background-size: contain

.tile.floor {

    background: url('https://i.imgur.com/7es7QMs.png') no-repeat; /* Remove no-repeat if you want it to tile */
    height: 38px; /* Whatever height you want */
    background-size: contain;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM