【问题标题】:How to insert an Image in css correctly [duplicate]如何在css中正确插入图像[重复]
【发布时间】:2020-08-31 00:56:54
【问题描述】:

我尝试使用 css 插入图像,问题是它适用于来自互联网的 http 图像,但是当我使用具有正确路径的本地图像时不起作用。

顺便说一句,我将图像放在 html 文件的同一文件夹中。 还使用可视代码中的右键单击复制路径。

这是css:

.cuerpo{
    background-image:url(""); 
    height: 100vh;
    background-size: bottom;
    display:flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

}

【问题讨论】:

  • 这是我使用 C:\Users\elari\OneDrive\Documents\CacheStudioOff\img\LampPostBannercache.jpg 的路径

标签: html css


【解决方案1】:

如果它在同一个文件夹中,请尝试此解决方案。

.cuerpo{
    background-image:url("filename.extension"); 
    height: 100px;
    background-size: bottom;
    display:flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

所以,你只需要在那里写 filename.extension。

【讨论】:

    【解决方案2】:

    如果您的图像与 .html 文件位于同一文件夹中,则应仅指定图像名称。例如background-image: url('image.jpg')

    【讨论】:

      猜你喜欢
      • 2014-01-09
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-09
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 2018-06-24
      相关资源
      最近更新 更多