0

Need help guys I have this HTML code:

<div class="editable">
  <div>
     <div class="column col1of5">
     </div>
     <div class="column col1of5"> 
     </div>
     <div class="column col1of5"> 
     </div>
     <div class="column col1of5">
     </div>
     <div class="column col1of5">  
     </div>
     </div>
  </div>

I want to select the last .col1of5 through css how can I do that?

3
  • Where is your html code ? Commented May 7, 2013 at 7:28
  • Calm down guys he didn't indent it. Commented May 7, 2013 at 7:28
  • stackoverflow.com/questions/7298057/… Commented May 7, 2013 at 7:29

3 Answers 3

2

Use this CSS to get the last child :

.parentDiv .col1of5:last-child {
    /* CSS */
}
Sign up to request clarification or add additional context in comments.

3 Comments

Nesting selectors and rules? That's new.
The OP didn't say he uses Compass, which is a framework that is not natively implemented in browsers. Your code is invalid as it stands. This question is not tagged compass.
Compass is just a way to build CSS more easily. But you're right, it's my fault, just the habits...
2

I just saw your HTML.

Here is the solution. refer this fiddle.

The HTML

<div class="editable">
  <div>
     <div class="column col1of5">1</div>
     <div class="column col1of5">2</div>
     <div class="column col1of5">3</div>
     <div class="column col1of5">4</div>
     <div class="column col1of5">5</div>
     </div>
  </div>

The CSS

.editable div {
    background: none repeat scroll 0 0 #292929;
    color: white;
    list-style: none outside none;
    padding-left: 0;
    width: 200px;
}
.editable div div {
    border-bottom: 1px solid black;
    border-top: 1px solid #3C3C3C;
    padding: 10px;
}
.editable div div:first-child {
    border-top: medium none;
}
.editable div div:last-child {
    border-bottom: medium none;
    color: red;
}

Hope this helps.

Comments

0

Try this:

.col1of5:last-child {
    /* my CSS rules */
}

:last-child is a pseudo selector and it points to the element that is the last child element of a certain node. It may sound logical enough but it can be confusing, since you may think it should be .editable:last-child. You should apply the selector to the child element itself, not the parent.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.