SweetAlert - 更改模态宽度?
SweetAlert - Change Modal Width?
我喜欢这个图书馆。我想用它在我的一个网页上显示适度的响应 table,但文本变得有点宽。我希望有一个选项可以更改我在 SweetAlert 中显示 table 的页面的整体警报宽度,但我没有任何运气。 Table & HTML 看起来很棒,只是模态的信息太多了。
我什至找不到整体中设置宽度的地方sweetalert.css。
我认为 customClass 配置键可能会有所帮助,我试过了:
swal({
title: priorityLevel +' Issues for '+appName,
html: appHTML,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false
});
css 很简单:
.swal-wide{
width:850px;
}
这没有做任何事情。任何人都知道如何做到这一点,或者可能玩过 width 元素?
谢谢!
试着把 !important
像这样放在 css:
.swal-wide{
width:850px !important;
}
在代码段中查看它的运行情况。
function TestSweetAlert(){
swal({
title: 1 +' Issues for test',
text: "A custom <span style='color:red;'>html</span> message.",
html: true,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false
});
};
$('#testeSWAL').on("click",TestSweetAlert);
.swal-wide{
width:850px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet"/>
<button id="testeSWAL"> Test SWAL </button>
Note: maybe you will have problems with the position.
SweetAlert 模态的 class 名称是 sweet-alert。所以,如果你想改变它的宽度,正确的 CSS 代码是:
.sweet-alert {
width: 850px;
}
这适用于 SweetAlert 1.1.3
而不是覆盖默认 .sweet-alert
css class 你可以定义你自己的
.sweet-alert.sweetalert-lg { width: 600px; }
只需使用 sweetalert 选项将您的 class 设置为您想要的警报:
swal({
title: "test",
text: "Am I wide?",
customClass: 'sweetalert-lg'
});
PS(更新):您可能需要稍微更改 sweetalert class 以使其正确居中:
.sweet-alert { margin: auto; transform: translateX(-50%); }
Here is jsbin 试试看
最好使用 SweetAlert2,它是 SweetAlert 的继承者。只需添加 "width" 属性,例如:
swal({
title: priorityLevel +' Issues for '+appName,
html: appHTML,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false,
width: '850px'
});
您可以使用的最新版本:
width: '800px'
即:
swal({
title: "Some Title",
html: "<b>Your HTML</b>",
width: '800px'
})
None 这里的答案对我有用。我所要做的就是将宽度值添加为整数(不带字符串)并删除 'px' 后缀。
swal({
width: 400,
html: data,
showCancelButton: true,
showConfirmButton:false,
cancelButtonText: "Close",
});
一个简单的解决方案是添加以下 CSS。参考:Sweet alert 2 modal shows too small
.swal2-popup { font-size: 1.6rem !important; }
Tried Everything , none Worked. The Only Thing which worked for me was to add a classname instead of custom class
在你的js中
swal({
title : "More Data",
className: "myClass"
});
在你的Css
.myClass{
width:600px;
height:auto;
}
您还可以将样式添加到 HTML 头部:
.swal-modal {
width: 1000px;
}
这对我有用。希望这有帮助
swal({
title: 'Title',
type: 'question',
width: '650px', /*set width container*/
showCancelButton: true,
showConfirmButton: true
});
如果您使用的是 https://sweetalert2.github.io/
上提供的 SweetAlert2
然后对于自定义宽度,您可以使用 Swal.fire() 函数的宽度 属性,例如
Swal.fire({
title: 'Custom width',
width: 600,
})
不是答案,但我希望我能帮助到别人。
在我的例子中,由于我的主题风格,modal 显得很小。所以将这个固定的矿井添加到默认大小。
.swal2-popup {
font-size: 1.6rem !important;
}
None 这对我有用。 "sweetalert2": "^11.2.0"
- 尝试过自定义 class
- 直接宽度 属性(有效但需要最大宽度,但不可用)
- 此外 classname 对我不起作用
最后不得不使用开发工具,检查元素并对 classes 进行必要的更改。以下是最近提醒框的一些变化。
.swal2-popup {
max-height: 300px !important;
max-width: 300px !important;
}
.swal2-icon {
font-size: 13px !important;
}
.swal2-text {
max-height: 70px;
}
.swal2-confirm {
background: #3aa9a9 !important;
}
如果不起作用,请在新选项卡中打开
虽然这里的大多数答案都有效,但我想补充两分钱。 (对于:Sweetalert2)
我们不应该使用固定大小,比如 width: 500/600/800
,因为它在较小的设备上可能看起来很难看。我宁愿建议使用百分比,这样无论您在哪种设备屏幕尺寸上使用它,它都会表现一致。
假设我们要显示一个不应超过屏幕大小 40% 的弹出窗口,那么我们可以像下面这样使用它:
Swal.fire({
title: 'Consistent width',
width: '40%',
})
如果我们在整个项目的所有 pop-ups 中使用相同的约定,我们将看到一致的 Sweet alerts
。
我喜欢这个图书馆。我想用它在我的一个网页上显示适度的响应 table,但文本变得有点宽。我希望有一个选项可以更改我在 SweetAlert 中显示 table 的页面的整体警报宽度,但我没有任何运气。 Table & HTML 看起来很棒,只是模态的信息太多了。
我什至找不到整体中设置宽度的地方sweetalert.css。
我认为 customClass 配置键可能会有所帮助,我试过了:
swal({
title: priorityLevel +' Issues for '+appName,
html: appHTML,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false
});
css 很简单:
.swal-wide{
width:850px;
}
这没有做任何事情。任何人都知道如何做到这一点,或者可能玩过 width 元素?
谢谢!
试着把 !important
像这样放在 css:
.swal-wide{
width:850px !important;
}
在代码段中查看它的运行情况。
function TestSweetAlert(){
swal({
title: 1 +' Issues for test',
text: "A custom <span style='color:red;'>html</span> message.",
html: true,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false
});
};
$('#testeSWAL').on("click",TestSweetAlert);
.swal-wide{
width:850px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet"/>
<button id="testeSWAL"> Test SWAL </button>
Note: maybe you will have problems with the position.
SweetAlert 模态的 class 名称是 sweet-alert。所以,如果你想改变它的宽度,正确的 CSS 代码是:
.sweet-alert {
width: 850px;
}
这适用于 SweetAlert 1.1.3
而不是覆盖默认 .sweet-alert
css class 你可以定义你自己的
.sweet-alert.sweetalert-lg { width: 600px; }
只需使用 sweetalert 选项将您的 class 设置为您想要的警报:
swal({
title: "test",
text: "Am I wide?",
customClass: 'sweetalert-lg'
});
PS(更新):您可能需要稍微更改 sweetalert class 以使其正确居中:
.sweet-alert { margin: auto; transform: translateX(-50%); }
Here is jsbin 试试看
最好使用 SweetAlert2,它是 SweetAlert 的继承者。只需添加 "width" 属性,例如:
swal({
title: priorityLevel +' Issues for '+appName,
html: appHTML,
type: "info",
customClass: 'swal-wide',
showCancelButton: true,
showConfirmButton:false,
width: '850px'
});
您可以使用的最新版本:
width: '800px'
即:
swal({
title: "Some Title",
html: "<b>Your HTML</b>",
width: '800px'
})
None 这里的答案对我有用。我所要做的就是将宽度值添加为整数(不带字符串)并删除 'px' 后缀。
swal({
width: 400,
html: data,
showCancelButton: true,
showConfirmButton:false,
cancelButtonText: "Close",
});
一个简单的解决方案是添加以下 CSS。参考:Sweet alert 2 modal shows too small
.swal2-popup { font-size: 1.6rem !important; }
Tried Everything , none Worked. The Only Thing which worked for me was to add a classname instead of custom class
在你的js中
swal({
title : "More Data",
className: "myClass"
});
在你的Css
.myClass{
width:600px;
height:auto;
}
您还可以将样式添加到 HTML 头部:
.swal-modal {
width: 1000px;
}
这对我有用。希望这有帮助
swal({
title: 'Title',
type: 'question',
width: '650px', /*set width container*/
showCancelButton: true,
showConfirmButton: true
});
如果您使用的是 https://sweetalert2.github.io/
上提供的 SweetAlert2然后对于自定义宽度,您可以使用 Swal.fire() 函数的宽度 属性,例如
Swal.fire({
title: 'Custom width',
width: 600,
})
不是答案,但我希望我能帮助到别人。 在我的例子中,由于我的主题风格,modal 显得很小。所以将这个固定的矿井添加到默认大小。
.swal2-popup {
font-size: 1.6rem !important;
}
None 这对我有用。 "sweetalert2": "^11.2.0"
- 尝试过自定义 class
- 直接宽度 属性(有效但需要最大宽度,但不可用)
- 此外 classname 对我不起作用
最后不得不使用开发工具,检查元素并对 classes 进行必要的更改。以下是最近提醒框的一些变化。
.swal2-popup {
max-height: 300px !important;
max-width: 300px !important;
}
.swal2-icon {
font-size: 13px !important;
}
.swal2-text {
max-height: 70px;
}
.swal2-confirm {
background: #3aa9a9 !important;
}
如果不起作用,请在新选项卡中打开
虽然这里的大多数答案都有效,但我想补充两分钱。 (对于:Sweetalert2)
我们不应该使用固定大小,比如 width: 500/600/800
,因为它在较小的设备上可能看起来很难看。我宁愿建议使用百分比,这样无论您在哪种设备屏幕尺寸上使用它,它都会表现一致。
假设我们要显示一个不应超过屏幕大小 40% 的弹出窗口,那么我们可以像下面这样使用它:
Swal.fire({
title: 'Consistent width',
width: '40%',
})
如果我们在整个项目的所有 pop-ups 中使用相同的约定,我们将看到一致的 Sweet alerts
。