less css using last-child selector

南笙酒味 提交于 2020-01-02 01:02:42

问题


I am using less and trying to get the last input to have a margin-bottom of 10px. Here is what I have, but it is not working, and not applying the margin-bottom on the last input. Any ideas why?

input {
  margin-bottom: 0px;

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

And the 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>

回答1:


Your last input is not the last child — that would be your button.

Use :last-of-type instead to select the last input:

input {
  margin-bottom: 0px;

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


来源:https://stackoverflow.com/questions/16404376/less-css-using-last-child-selector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!