简体   繁体   English

如何对齐 HTML5 表单验证气泡消息?

[英]How to align the HTML5 form validation bubble messages?

When HTML5 form contains required fields , such asHTML5表单包含必填字段时,例如

<input placeholder="Name" required>

or或者

<textarea placeholder="message" required>

...and such field is submitted empty, Google Chrome (and perhaps also some other browsers) shows the invalid validation bubble message like this: ...并且此类字段提交为空,Google Chrome(也许还有其他一些浏览器)显示无效的验证气泡消息,如下所示:

在此处输入图像描述

...which by default has center alignment. ...默认情况下具有中心 alignment。 Is it be possible to force to display such bubble message on left, like this: ?是否可以强制在左侧显示此类气泡消息,如下所示:?

在此处输入图像描述


I am not trying to style this bubble message, therefore please do not consider this post as a duplicate to other posts that ask for change of appearance/style.我不想为这条气泡消息设置样式,因此请不要将此帖子视为与其他要求更改外观/样式的帖子的重复。

The best workaround for this is to prevent a default behavior by最好的解决方法是通过以下方式防止默认行为

document.addEventListener('invalid', (function () {
  return function (e) {
    e.preventDefault();
  };
})(), true);

...and to add own visual appearance, such as ...并添加自己的视觉外观,例如

input:invalid, textarea:invalid 
{
  background: rgba(255, 64, 64, 0.1);
  border-color: rgb(255, 64, 64);
}

...and surely, own bubble message can be designed and added, if desired. ...当然,如果需要,可以设计和添加自己的气泡消息。

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

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