【问题标题】:No local image path will show up in css background urlcss 背景 url 中不会显示本地图像路径
【发布时间】:2020-12-15 09:49:40
【问题描述】:

我刚刚在这里覆盖了引导程序,并确保它是从我的本地 css 中提取的,对它的任何其他更改都可以工作,但是当我尝试插入背景图像时,只有 localhost url 用于图像工作,如果我指定本地路径它没有。我尝试了所有变体,也是静态的背景图像: url("{% static 'portfolio/waterfall.jpg' %}"); 我正在使用 Django,之前我的 settings.py 出现了问题-这会导致它吗?谢谢 #settings.py

STATIC_URL = '/static/'

MEDIA_ROOT = BASE_DIR / 'media'

MEDIA_URL = '/media/'

#this is the jumbotron Im试图获取背景

<section class="jumbotron text-center">
<div class="container">
  <h1>Album example</h1>
  <p class="lead text-muted">Something short and leading about the collection below—its contents, the 
creator, etc. Make it short and sweet, but not too short so folks don’t simply skip over it entirely. 
  </p>
  <p>
    <a href="#" class="btn btn-primary my-2">Main call to action</a>
    <a href="#" class="btn btn-secondary my-2">Secondary action</a>
  </p>
</div>
</section>

#和自定义的.css

.jumbotron {
padding: 2rem 1rem;
margin-bottom: 2rem;
background-color: #c5b8b8;
border-radius: .3rem;
background-image: 
url("media/portfolio/images/foster-s-home-for-imaginary-friends-fosters-home-for-imaginary-friends-_ER46ne1.jpg");
background-repeat: no-repeat;
background-position: bottom center;
background-size: cover;
}

【问题讨论】:

    标签: html css django bootstrap-4


    【解决方案1】:

    图片地址错误,正确的是https://commons.wikimedia.org/wiki/File:Image_created_with_a_mobile_phone.png

    阅读许可以及可用的大小和格式,然后下载并在您的服务器上保存适合您网站的文件版本。使用指向特定版本的直接链接是可能的,但滥用 wiki 传输是不礼貌的。


    编辑
    您是否在元声明中引导后插入了自定义 css?
    如果不怪 url 和 order 则坏消息 - 问题更大并且依赖于引导程序。
    好吧,在浏览器中使用https://validator.w3.org/unicorn/ 和开发工具来找出问题所在

    【讨论】:

    • 是的,好吧,我不是故意滥用服务器,里面的图片只是一个例子来说明点。可悲的是它并没有解决我的问题
    • @doctorprofessor 没有冒犯,作为新成员,您可以获得很多先验提示,有时也可以获得布道(为了您自己的利益);我已经扩展了我的答案 - 我希望它有所帮助
    猜你喜欢
    • 2014-11-30
    • 2020-05-15
    • 2014-03-31
    • 1970-01-01
    • 2016-01-09
    • 2018-07-10
    • 2012-12-11
    • 2019-02-27
    • 2015-02-18
    相关资源
    最近更新 更多