如何仅使用 css 设置默认确认框的样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6185152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:39:32  来源:igfitidea点击:

How to style default confirm box with only css?

cssconfirm

提问by opportunato

I would like to style standard window.confirm without using any additional JavaScript code, only with CSS. Is it even possible? And if it is, how can I do it?

我想在不使用任何额外的 JavaScript 代码的情况下设置标准 window.confirm 的样式,只使用 CSS。甚至有可能吗?如果是,我该怎么做?

回答by solendil

It is not possible. This window is displayed by the browser using the platform's UI kit. It's not in the DOM, not visible from the CSS or Javascript, there's nothing you can do.

这不可能。该窗口由浏览器使用平台的 UI 工具包显示。它不在 DOM 中,在 CSS 或 Javascript 中不可见,您无能为力。

However, some very simple jQuery code can do the trick. How about $('a').confirm();?

然而,一些非常简单的 jQuery 代码可以做到这一点。怎么样$('a').confirm();

回答by shearnonsense

confirm();alerts cannot be styled, they are generic to the browser. If you want to style an alert, try alternatives such as boxy, or the jQuery dialog box.

confirm();警报不能设置样式,它们是浏览器通用的。如果要设置警报样式,请尝试使用boxyjQuery dialog box等替代方法。

Hereis a tutorial about how a custom confirm alert can be created in jQuery and styled with CSS.

是一个关于如何在 jQuery 中创建自定义确认警报并使用 CSS 设置样式的教程。

回答by Mikko-Pentti Einari Eronen

This is a very old question. But I felt the need to pass this info here. I noticed that you can "style" the confirm with special characters, such as \n, \t, \r, ... so on.

这是一个非常古老的问题。但我觉得有必要在这里传递这些信息。我注意到您可以使用特殊字符“样式化”确认,例如 \n、\t、\r、...等。