【问题标题】:Is there another way to set background image?还有另一种设置背景图像的方法吗?
【发布时间】:2021-03-04 06:56:36
【问题描述】:

将background-image: url() 标签添加到我的代码时遇到问题。它不显示。我已经尝试了一切,添加了字符串,使其成为该块中的第一个,但没有任何效果。很郁闷。

HTML:

<div id="home" class="offset">
      <div class="landing">
        <div class="home-wrap">
          <div class="home-inner"></div>
        </div>
      </div>

CSS:

.home-inner {
  background-image: url("imgs\04-full.jpg");
  position: relative;
  background-size: cover;
}

【问题讨论】:

标签: html css background-image


【解决方案1】:

发生这种情况是因为带有background-image 属性的div 没有大小,因此它显示在html 页面中,但它的宽度和高度为空。

.home-inner {
  background-image: url(https://www.gravatar.com/avatar/062021b6a1aae23a9651e9ab01ec9e36?s=48&d=identicon&r=PG&f=1);
  position: relative;
  background-size: cover;
  width: 500px; /* fixed width */
  height: 500px;  /* fixed height */
}
<div id="home" class="offset">
      <div class="landing">
        <div class="home-wrap">
          <div class="home-inner"></div>
        </div>
      </div>

尝试向其添加一些内容或给 div 一些 width 和 height

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-24
    • 2015-09-08
    • 2011-06-24
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多