【问题标题】:less css using last-child selector使用 last-child 选择器减少 css
【发布时间】:2013-04-30 12:58:45
【问题描述】:

我正在使用less 并试图让last 输入具有10pxma​​rgin-bottom。这是我所拥有的,但它不起作用,并且没有在最后一个输入上应用 margin-bottom 。任何想法为什么?

input {
  margin-bottom: 0px;

  &:last-child {
    margin-bottom: 10px;
  }
}

还有 HTML

<form id="auth-form">
  <input id="ember367" class="ember-view ember-text-field" placeholder="Email" type="email" name="email">
  <input id="ember368" class="ember-view ember-text-field" placeholder="Password" type="password" name="password">
  <div class="clear"></div>

  <a class="pull-left forgot-password">Forgot password?</a>
  <button class="pull-right" data-ember-action="1" type="button">Sign In</button>
</form>

【问题讨论】:

    标签: css css-selectors less


    【解决方案1】:

    您最后一个input 不是最后一个孩子——那将是您的button

    使用:last-of-type 来选择最后一个input

    input {
      margin-bottom: 0px;
    
      &:last-of-type {
        margin-bottom: 10px;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多