【问题标题】:Change css style HTML5 form required attribute required message更改 CSS 样式 HTML5 表单必填属性必填消息
【发布时间】:2014-01-20 10:47:12
【问题描述】:

我为 RTL 项目与 RTLbootstrap 合作。现在我有任何带有 HTML5 表单必需属性必需消息 的表单。在行动中,我有这个气球作为输入:

我需要像这样为 RTL 进行更改:

HTML:

<div class="controls">
  <input class="span4" type="text" name="title" placeholder="Title"  value=""  required oninvalid="this.setCustomValidity(\'User ID is a must\')">
</div>

注意:这不是自定义工具提示或气球!如果我们在表单输入中添加所需的 html 标签。在提交表单HTML5 form required attribute 之前自动显示此气球消息。我需要为验证消息编辑/更改/设置 CSS?

如何更改 rightinput 字段中显示的必填字段消息的显示?

【问题讨论】:

  • 我看到的只是工具提示的三角形部分……你可以在“span4”类或“控件”类(无论工具提示所在的位置)中编辑它吗? ?
  • 这会因浏览器而异,例如,您在 Firefox 上看到了这个,但 Chrome 有一些完全不同的东西,IE 也是如此。确保这在所有浏览器中都能正常工作并看起来相同的唯一方法是构建您自己的验证。

标签: jquery css html


【解决方案1】:

Chrome 不再允许为表单验证气泡设置样式:

See Details

Firefox 无法设置错误气泡样式

See Details

【讨论】:

    【解决方案2】:

    嘿,我在这里找到了一个链接,他们使用了这个技巧。他们在输入类型上附加了一个类。并在那里显示消息。希望在进行少量定制后有所帮助。 工作代码笔:http://codepen.io/smarty_tech/pen/ONZRVp

    <form id="frm" action="action">
    <div>
    <label>Email</label>
      <input type="email" required="required"/><span class="theTooltip">Invalid email</span>
     </div>
     <div>
      <button formnovalidate="formnovalidate">OK</button>
    </div>
    

     document.querySelector('#frm').addEventListener('submit', e => {
       e.preventDefault();
       e.currentTarget.classList.add('submitted');
     });
    
      body
      font-family: Helvetica, sans-serif
     display: flex
     flex-direction: column
    align-items: center
     justify-content: center
    overflow: hidden
    width: 100%
     height: 100vh
      background orange
    
     form > div
      position: relative
      margin-bottom: 10px
    
     .theTooltip
      $bgcolor = rgba(black, 0.7)
      $arrow = 10
      $radius = 5
      $maxWidth = 250
      $padding = 15
      backface-visibility: hidden
      will-change: opacity, visibility
      max-width: $maxWidth * 1px
      border-radius: $radius * 1px
      background-color: $bgcolor
      padding: $padding * 1px
      color: white
      box-sizing: border-box
      display: inline-block
      position: absolute
      transform-style: preserve-3d
      transform: translate(15%, -50%)
      top: 50%;
      left: auto
      right: auto
      bottom: auto
      visibility: hidden
      margin: 0
      opacity: 0
      transition: opacity 0.3s ease-out
      z-index: 100
      &:after
      content: ''
      position: absolute
      width: 0
       height: 0
      top: 50%
    margin-top: $arrow * -1px
    left: $arrow * -1px
    border-top: $arrow * 1px solid transparent
    border-bottom: $arrow * 1px solid transparent
    border-right: $arrow * 1px solid $bgcolor
    
      label
     display: inline-block
     vertical-align: center
    
    input
    background: white
    border: 1px solid transparent
    cursor: pointer
    display: inline-block
    overflow: visible
    margin: 0
    outline: 0
    vertical-align: center
    text-decoration: none
    width: auto
    border-radius: 3px
    cursor: text
    padding: 7px
    &:focus
    &:active
    outline: none
    
     .submitted
      input
      &:invalid
        border: 1px solid red
        ~ .theTooltip
           visibility: visible
          opacity: 1
      &:valid
        ~ .theTooltip
          transition: opacity 0.3s, visibility 0s 0.3s
    

    【讨论】:

      【解决方案3】:

      Example of Message with only css3

      代码:

      .tooltip, .arrow:after {
        background: black;
        border: 2px solid white;
      }
      
      .tooltip {
        pointer-events: none;
        opacity: 0;
        display: inline-block;
        position: absolute;
        padding: 10px 20px;
        color: white;
        border-radius: 20px;
        margin-top: 20px;
        text-align: center;
        font: bold 14px "Helvetica Neue", Sans-Serif;
        font-stretch: condensed;
        text-decoration: none;
        text-transform: uppercase;
        box-shadow: 0 0 7px black;
      }
      .arrow {
        width: 70px;
        height: 16px;
        overflow: hidden;
        position: absolute;
        left: 50%;
        margin-left: -35px;
        bottom: -16px;
      }
      .arrow:after {
         content: "";
         position: absolute;
         left: 20px;
         top: -20px;
         width: 25px;
         height: 25px;
         -webkit-box-shadow: 6px 5px 9px -9px black,5px 6px 9px -9px black;
         -moz-box-shadow: 6px 5px 9px -9px black,5px 6px 9px -9px black;
         box-shadow: 6px 5px 9px -9px black,5px 6px 9px -9px black;
        -webkit-transform: rotate(45deg);
        -moz-transform:    rotate(45deg);
        -ms-transform:     rotate(45deg);
        -o-transform:      rotate(45deg); 
      }
      .tooltip.active {
        opacity: 1;
        margin-top: 5px;
        -webkit-transition: all 0.2s ease;
        -moz-transition:    all 0.2s ease;
        -ms-transition:     all 0.2s ease;
        -o-transition:      all 0.2s ease;
      }
      .tooltip.out {
        opacity: 0;
        margin-top: -20px;
      }
      

      【讨论】:

        猜你喜欢
        • 2019-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-01
        • 1970-01-01
        • 2021-03-30
        相关资源
        最近更新 更多