【问题标题】:How to make MetroCSS label always shown?如何使 MetroCSS 标签始终显示?
【发布时间】:2015-11-26 16:47:06
【问题描述】:

有一个input-control 有一个label

<div class="input-control modern text" data-role="input">
    <input name="salle_lib" id="salle_lib" type="text" maxlength="70" placeholder="libell&eacute;" data-validate-func="required" data-validate-hint="Ce champ est obligatoire"/>
    <button class="button helper-button clear"><span class="mif-cross"></span></button>
    <span class="label">libell&eacute;</span> // this is the label
</div>

MetroCSS 的默认行为是当点击input-control 时会显示标签:

.input-control.text > .label {
  position: absolute;
  left: 0;
  top: -1rem;
  font-size: .875rem;
}
.input-control.modern input:focus ~ .label {
  opacity: 1;
  -webkit-transform: translateY(-18px);
          transform: translateY(-18px);
  transition: all 0.3s linear;
}

即使未单击输入控件,我也希望始终显示此标签。我试过$(".input-control.text").click(); 但没用!那么该怎么做呢?

这里是jsfiddle

【问题讨论】:

  • 我在最后的问题中包含了 jsfiddle。

标签: jquery css metro-ui-css


【解决方案1】:

只需将此 CSS 添加到您的页面

.input-control.modern input ~ .label {
    opacity: 1;
    transform: translateY(-18px);
    transition: all 0.3s linear 0s;
}

【讨论】:

    【解决方案2】:

    关键是使用focus。我认识谁?因为可以看到css的选择器例如:.input-control.modern input:focus ~ .label

    $('input').trigger('focus');
    /* if you want to avoid the animation at the start
    
    .modern.text * {
      transition:none !important;  
    }
    
    */
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://metroui.org.ua/js/metro.js"></script>
    <link href="http://metroui.org.ua/css/metro.css" rel="stylesheet">
    
    <div class="input-control modern text " data-role="input">
        <input type="text" style="padding-right: 5px;">
        <span class="label">You login</span>
        <span class="informer">Please enter you login or email</span>
        <span class="placeholder" style="display: block;">Input login</span>
    </div>

    更新演示:jsbin

    【讨论】:

    • 我运行了你的代码 sn-p 但开始时没有显示带有类标签的跨度!
    • 在您的 sn-p 中,我必须单击该字段以显示标签!这不是我的目标!即使我不点击该字段,我也希望在开始时显示标签!
    • 在我的检查中,sn-p 执行此操作。你用什么浏览器?
    • 那是因为 Firefox 阻止了 metro 资源的 https 链接。请检查:output.jsbin.com/wafowe
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2021-01-21
    • 2011-01-27
    相关资源
    最近更新 更多