简体   繁体   English

HTML5 - 如何将 CSS 应用于验证器消息

[英]HTML5 - How to aply CSS to validator message

I'm trying (with no results) to aply a simple custom width to this validator message:我正在尝试(没有结果)将此验证器消息应用一个简单的自定义宽度:

在此处输入图片说明

How can i do it ?我该怎么做 ?

UPDATE: I mean, the message which says " Please select an item from the list " we can supose it has, by default, a width=100px .更新:我的意思是,“ Please select an item from the list ”的消息我们可以假设它默认具有width=100px How can i change this default width to 300px ?如何将此默认宽度更改为300px

This question has already been answered.这个问题已经有了答案。 You can find the answer here .您可以在此处找到答案。 For ease of access the code you'll need is below.为了便于访问,您需要的代码如下。

::-webkit-validation-bubble

::-webkit-validation-bubble-arrow-clipper 

::-webkit-validation-bubble-arrow 

::-webkit-validation-bubble-message 

This is Chrome's implementation of styling, however it is not officially standard.这是 Chrome 的样式实现,但它不是官方标准。 Hence consider creating your own popup.因此,请考虑创建自己的弹出窗口。


Setting content of bubble气泡设置内容

Please consider adding what you have already attempted and what results you would expect.请考虑添加您已经尝试过的内容以及您期望的结果。

$(document).ready(function() {
    var elements = document.getElementsByTagName("INPUT");
    for (var i = 0; i < elements.length; i++) {
        elements[i].oninvalid = function(e) {
            e.target.setCustomValidity("");
            if (!e.target.validity.valid) {
                e.target.setCustomValidity("This field shouldn't be left blank/please select an option!");
            }
        };
        elements[i].oninput = function(e) {
            e.target.setCustomValidity("");
        };
    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM