【问题标题】:How to use two background images如何使用两个背景图像
【发布时间】:2017-04-27 01:37:43
【问题描述】:

我在我的网站中使用 Bootstrap 模式。我想使用两张图片作为背景。我能够成功使用一张图片。当我尝试添加第二张图片时,我遇到了问题。

我的第一张图片出现在整个模态框上,第二张图片很小,但我希望它出现在第一张图片的顶部。

我的第一张图片的 CSS 代码是

.modal-content{
    background-image: url("{% static "markatix/imgs/modal/bg.png" %}");
}

我尝试了this question 中的解决方案,但是当这样写时,我的第一张图片也消失了。

我也试过了

.modal-content{
    background-image: url("{% static "markatix/imgs/modal/bg.png" %}") ,url("{% static "markatix/imgs/modal/bg2.png" %}") ;
    background-repeat: no-repeat,no-repeat;
    background-position: center, center;
}

但是它只显示了一张图片。

【问题讨论】:

  • 你能发布你的HTML代码吗

标签: jquery html css image twitter-bootstrap


【解决方案1】:

在这里阅读:http://www.w3schools.com/css/css3_backgrounds.asp

#example1 {
    background-image: url(http://www.thedesignwork.com/wp-content/uploads/2011/10/Random-Pictures-of-Conceptual-and-Creative-Ideas-02.jpg), url(https://s-media-cache-ak0.pinimg.com/originals/f5/9b/1b/f59b1b0cc430702e82dea90780d7f87d.gif);
    background-position: right bottom, left top;
    background-repeat: no-repeat, no-repeat;
    background-size: 20%, 20%;
    height: 100vh;
    width: 100%;
}
<div id="example1"></div>

【讨论】:

【解决方案2】:

你应该在这个之上包含另一个 div

您可以通过调整外部的填充来调整内部的位置和大小

 .main-div{
      margin:0;
      padding:50px;
      width:300px;
      height:200px;
      background-image:url("https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Geres1.jpg/480px-Geres1.jpg");
      background-size:cover;
      background-repeat:no-repeat;
      background-position:center;
    }
    
    .overlay-div{
      margin:auto;
      padding:0;
      width:100%;
      height:100%;
      background-image:url('https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Venus_globe.jpg/480px-Venus_globe.jpg');
      background-size:cover;
      background-repeat:no-repeat;
      background-position:center;
    }
 <div class="main-div">
      <div class="overlay-div">
      </div>
      </div>

【讨论】:

  • 我认为浏览器与其他多 CSS 后台解决方案的兼容性存在很大差异......我认为这在 100% 的情况下有效,而其他解决方案经常失败。你碰巧知道具体有什么区别吗?
猜你喜欢
  • 1970-01-01
  • 2016-03-14
  • 2016-05-18
  • 1970-01-01
  • 2021-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-07
相关资源
最近更新 更多