我想问一下,在我的模态框中是否可以设置背景图片?我试过搜索,但我只看到与模态框有关的背景内容是指页面本身。我想要的是在模态框上放置一个带有图像背景的模态框。或者改变它的颜色?谢谢。我不太擅长CSS。谢谢。
我想问一下,在我的模态框中是否可以设置背景图片?我试过搜索,但我只看到与模态框有关的背景内容是指页面本身。我想要的是在模态框上放置一个带有图像背景的模态框。或者改变它的颜色?谢谢。我不太擅长CSS。谢谢。
.modal-body {
background-image: url(path/to/image);
}
.modal-backdrop {
background-image: url(path/to/image);
}
是的,只需使用 background-image: url(你的图片路径);
$('#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">×</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>
.modal-body {
background-size: cover;
background-image: url("./bg_image.png");
}
.modal-content {
background-size: cover;
background-image: url("./bg_image.png");
}
编辑:我使用的模态框是从这里直接复制的标准模态框。
我假设您正在使用Bootstrap。
<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");
}