Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less css using last-child selector

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>
like image 765
Justin Avatar asked May 06 '13 17:05

Justin


People also ask

How do I skip the last child in CSS?

The :not() selector excludes the element passed to it from selection. The :last-child selector selects the last child. Combining these two above selector to excludes the last children (inner-div) of every parent div from the selection.

How do I select all except last child?

When designing and developing web applications, sometimes we need to select all the child elements of an element except the last element. To select all the children of an element except the last child, use :not and :last-child pseudo classes.

How do I get the last 5 child in CSS?

The :nth-last-child(n) selector matches every element that is the nth child, regardless of type, of its parent, counting from the last child. n can be a number, a keyword, or a formula.

Is last child CSS?

The :last-child selector allows you to target the last element directly inside its containing element. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.


1 Answers

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;
  }
}
like image 55
BoltClock Avatar answered Sep 30 '22 14:09

BoltClock