最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing the Overlay background color of sweet alert 2 - Stack Overflow

programmeradmin11浏览0评论

I have recently moved sweet alert 1 to sweet alert 2, but based on the documentation there is no option for theming the overlay background of an alert box like sweet alert 1

.swal-overlay {
  background-color: rgba(43, 165, 137, 0.45);
}.

Please how can I achieve changing the overlay background of sweet alert 2?

I have recently moved sweet alert 1 to sweet alert 2, but based on the documentation there is no option for theming the overlay background of an alert box like sweet alert 1

.swal-overlay {
  background-color: rgba(43, 165, 137, 0.45);
}.

Please how can I achieve changing the overlay background of sweet alert 2?

Share Improve this question edited Nov 16, 2017 at 4:53 Hayden Passmore 1,1552 gold badges12 silver badges35 bronze badges asked Oct 28, 2017 at 2:32 Eshiett Oto-obongEshiett Oto-obong 4181 gold badge4 silver badges16 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 6
Swal.fire({
  icon: 'success',
  background: 'red',
})

To achieve this you can just use jQuery selectors and select the overlay element like so.

<button type="button" onclick="opentheSwal();">OK</button>
<script>
    function opentheSwal() {
        swal(
            'Good job!',
            'You clicked the button!',
            'success'
        );
        $(".swal2-modal").css('background-color', '#000');//Optional changes the color of the sweetalert 
        $(".swal2-container.in").css('background-color', 'rgba(43, 165, 137, 0.45)');//changes the color of the overlay
    }
</script>

You will have to select the .swal2-container.in to change the overlay and apply the css using jqueries .css() function.

Good Luck.

I had this same issue, and found it was necessary to add !importantto the CSS:

.swal2-container.swal2-backdrop-show, .swal2-container.swal2-noanimation {
    background: rgba(0,0,0,.95)!important;
}
发布评论

评论列表(0)

  1. 暂无评论