I also have to show (a lot of) text with swal(2) and want to show the most of the text left aligned and the last line centered.
First, I have tried to apply css with customClass: 'swal-breit',
and set the width and alignment in the css.
But this don't work for my case...
As css don't seems to work for my case, I have implemented it with HTML (paragraph and align). In my (juery) function (with the embedded swal), I first create a variable with the html code and then set the property html:
to the variable.
Short description:
First a lot of text is showed (left aligned), then a question is showed (centered).
If the user clicks 'Ja' (Yes), a specific page (view) is loaded, if he clicks 'Nein' (No), nothing happens (swal ist closed an the user remains on the page (view).
Code snipped(simplified to post here) (German):
function MySwalFunction() {
var Meldungstext = "";
Meldungstext = Meldungstext + '<p align="left"> text in paragraph here.. <strong>strong text kere...</strong> further normal text with line break. <br>'
Meldungstext = Meldungstext + 'Second line of text </p>'
Meldungstext = Meldungstext + '<p align="left"> second paragraph block.. with linebreak <br>'
Meldungstext = Meldungstext + 'second line to second block </p>'
Meldungstext = Meldungstext + '<p align="left">tex ti third paragraph here </p>'
Meldungstext = Meldungstext + '<strong>Last line WITHOUT paragraph = is showed centered (swal default) </strong>'
swal.fire({
title: '! Achtung !',
html: Meldungstext,
icon: 'question',
showCancelButton: true,
width: '90%',
confirmButtonColor: 'blue',
cancelButtonText: 'Nein',
confirmButtonText: 'Ja',
}).then(function (result) {
if (result.value) {
var hostname = window.location.origin;
var xlink = hostname + "/main/sub/"
location.href = xlink;
}
else {
}
})
}