admin管理员组文章数量:1208155
I define a className to customize a sweetAlert2 but apparently the styling wont apply to the sweet alert. I called the class name everything but nothing seems to work. could the problem be with main css file for this package ?
swal.fire({
title: Welcome,
className: styleTitle
});
The CSS
.styleTitle{
font-size: 25px;
}
I define a className to customize a sweetAlert2 but apparently the styling wont apply to the sweet alert. I called the class name everything but nothing seems to work. could the problem be with main css file for this package ?
swal.fire({
title: Welcome,
className: styleTitle
});
The CSS
.styleTitle{
font-size: 25px;
}
Share
Improve this question
edited Apr 13, 2021 at 20:19
Keneil Smith
asked Apr 13, 2021 at 20:07
Keneil SmithKeneil Smith
531 gold badge1 silver badge6 bronze badges
2 Answers
Reset to default 13I found this on the documentation it may help you.
Apparently you have to define customClass
instead of className
.
Here is an example.
.confirm-button-class {
background-color: red !important;
color: white !important;
border: none !important;
}
.title-class {
font-size: 15px !important;
}
.icon-class {
font-size: 10px !important;
}
.confirm-button-class .swal2-icon svg {
width: 12px !important;
height: 12px !important;
}
.swal2-actions .swal2-confirm {
background-color: #f1c40f !important;
color: white !important;
border: none !important;
box-shadow: none !important;
}
.swal2-actions .swal2-cancel {
border-color: #f1c40f !important;
box-shadow: none !important;
border: none !important;
}
.swal2-confirm:focus, .swal2-cancel:focus {
box-shadow: none !important;
border: none !important;
}
.swal2-actions button:hover {
border: none !important;
}
below is the customized sweetalert2
Swal.fire({
icon: 'warning',
title: 'Are you sure?',
text: 'This action cannot be undone.',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
customClass: {
confirmButton: 'confirm-button-class',
title: 'title-class',
icon: 'icon-class'
},
html: `
<div style="max-height: 300px; overflow-y: scroll;">
${allItems.map((item) => `
<div key="${item.asset_number}">
<div>
<p>Name: ${item.name}</p>
<p>Address: ${item.address}</p>
</div>
<hr style="border-color: gray; border-width: 1px; margin: 10px 0;" />
</div>
`).join('')}
</div>
`,
}).then((result) => {
if (result.isConfirmed) {
Swal.fire('Deleted!', 'Your item has been deleted.', 'success');
} else if (result.isDismissed) {
Swal.fire('Cancelled', 'Your item is safe :)', 'error');
}
});
Hope this will help you.
本文标签: javascriptCustom styling for Sweet alert 2Stack Overflow
版权声明:本文标题:javascript - Custom styling for Sweet alert 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738761668a2110998.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论