gpt4 book ai didi

html - 如何在图像标签上显示来自某个类的图像

转载 作者:太空宇宙 更新时间:2023-11-04 00:02:33 25 4
gpt4 key购买 nike

我的 html 中有一个图片标签:

<img class="fruit1" />

以及我的 CSS 中的以下内容:

.fruit1 {
background-image: url('./images/apple.png');
}

但我无法显示实际图像,这是在 css 中分配图像并在 View 中显示的正确方法吗?

最佳答案

<style>
.fruit1 {
background-image: url('./images/apple.png');
height:100px;
width:100px;
background-repeat:no-repeat;
}
</style>

<img class="fruit1" />

关于html - 如何在图像标签上显示来自某个类的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com