Bootstrap 模态图像背景
Bootstrap Modal Image Background
只是想问一下是否可以在我的模态中有背景图片?我试过搜索,但我只在模式上看到与背景相关的东西,它指的是页面本身。我想要的是我的模态框上面有图像背景。还是换个颜色?谢谢。我在 CSS 方面表现不佳。谢谢
是的,只需使用 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">×</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-image: url(path/to/image);
}
或者如果你想把它放在你的模式后面,你可以使用
.modal-backdrop {
background-image: url(path/to/image);
}
我假设您使用的是来自
的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");
}
我通过以下代码得到了所需的结果,可能对某人有帮助:
只在正文中显示试衣图像:
.modal-body {
background-size: cover;
background-image: url("./bg_image.png");
}
用于在 Complete Modal 中显示合适的图像(包括页眉和页脚):
.modal-content {
background-size: cover;
background-image: url("./bg_image.png");
}
编辑:我使用的模态是直接从here
复制的标准模态
只是想问一下是否可以在我的模态中有背景图片?我试过搜索,但我只在模式上看到与背景相关的东西,它指的是页面本身。我想要的是我的模态框上面有图像背景。还是换个颜色?谢谢。我在 CSS 方面表现不佳。谢谢
是的,只需使用 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">×</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-image: url(path/to/image);
}
或者如果你想把它放在你的模式后面,你可以使用
.modal-backdrop {
background-image: url(path/to/image);
}
我假设您使用的是来自
的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");
}
我通过以下代码得到了所需的结果,可能对某人有帮助:
只在正文中显示试衣图像:
.modal-body {
background-size: cover;
background-image: url("./bg_image.png");
}
用于在 Complete Modal 中显示合适的图像(包括页眉和页脚):
.modal-content {
background-size: cover;
background-image: url("./bg_image.png");
}
编辑:我使用的模态是直接从here
复制的标准模态