Bootstrap模态图像背景

问题描述 投票:3回答:3

只是想问一下我的模态中是否可以有背景图像?我尝试过搜索,但我只看到模态的背景相关内容,它指的是页面本身。我想要的是我的模态框,上面有图像背景。或改变它的颜色?谢谢。我在CSS方面不是那么好。谢谢。

css twitter-bootstrap modal-dialog bootstrap-modal
3个回答
6
投票

假设您想在模态体中使用图像,则可以使用

.modal-body {
   background-image: url(path/to/image);
}

或者如果你想要它在你的模态后面你可以使用

.modal-backdrop {
   background-image: url(path/to/image);
}

1
投票

我假设您正在使用引导程序

<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>

你需要编辑你的

<div class="modal-content">
    ...
</div>

至:

<div class="modal-content modal-popout-bg">

CSS:

.modal .modal-popout-bg {
    background-image: url("http://somepic.com/somepic.jpg");
}

0
投票

是的,只需使用background-image: url(path/to/your/image);

$('#myModal').modal() 
.modal-body {
    background-image: url('http://myfunnymemes.com/wp-content/uploads/2015/04/Doge-Meme-Lion-In-All-Its-Majestic-Glory.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css">

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        test
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.