CSS Apply Styling to All Elements Except Those in The Last Row

css apply styling to all elements except those in the last row

I think I figured this out. The second ruleset below accounts for any amount of products on the last row.

.products li:nth-child(3n){
border-bottom: 1px rgba(51, 51, 51, 0.1) solid;
}

.products li:nth-last-child(-n + 3):nth-child(3n + 1),
.products li:nth-last-child(-n + 3):nth-child(3n + 1) ~ li {
border: none;
}

http://jsfiddle.net/6rso3t85/

A better fiddle, adjusting the display as asked, and showing the three use cases

http://jsfiddle.net/6rso3t85/1/

How can I select all children of an element except the last child?

You can use the negation pseudo-class :not() against the :last-child pseudo-class. Being introduced CSS Selectors Level 3, it doesn't work in IE8 or below:

:not(:last-child) { /* styles */ }

How to target all elements, except last one with css?

If you number of levels inside .outer is known (or limited) you can extend selector like this:

.outer > * > a,.outer > a:not(:last-of-type) {    color: red;}
<div class="outer">  <a href="#">First</a>  <a href="#">Second</a>  <div>    <a href="#">Third</a>  </div>  <a href="#">Fourth</a>  <a href="#">Fifth</a></div>

Apply CSS Style on all elements except with a SPECIFIC ID

Use the :not selector:

div:not(#bar){    color:red;}
<div>foo</div><div id="bar">bar</div>

CSS nth-child expression to avoid the last row with at most 3 elements

So far, I've created a selector that applies a style to the last row

/* all the cells */
li {
background: #ccc;
}

/* last row, doesn't matter how many cells */
li:nth-last-child(-n + 3):nth-child(3n + 1), /* first element of the last row */
li:nth-last-child(-n + 3):nth-child(3n + 1) ~ li /* all its following elements */
{
/* reset the style, eg: */
background: transparent;
}

You can see a live example here http://jsbin.com/ufosox/1/edit

Of course this doesn't support IE8 and less.

Select all except first and last td element in one selector

It is syntactically correct, as you can quickly check using the W3C CSS Validator. The validator is known to have errors, so in principle, you should check the rule against CSS specifications, especially Selectors Level 3. The result is still that yes, it is correct.

It also has the desired meaning, since this is how selectors combine. You can use :not(...) selectors to express a condition of type “not ... and not ...”.

This applies provided that all children of tr elements are td. If there are header cells, i.e. th elements as well, then the selector applies to those data cells (td elements) that are not the first data cell or the last data cell in a row with .red class.

Is there any way to specify a CSS shorthand for all elements except the first/last?

For all p elements except the first child, use either one of these (the second one is better-supported):

p:not(:first-child)
p:first-child ~ p

For all p elements except the last child:

p:not(:last-child)

For all p elements except the first and the last children:

p:not(:first-child):not(:last-child)

As usual, CSS3's :not() and :last-child aren't supported until IE9+ and relatively new versions of other browsers. You're not going to reach very far in terms of browser support (IE8 and older) unless you add classes to your first and last children, using JavaScript or otherwise.

Remember that vertical margins collapse between in-flow paragraphs and their ancestor(s), so unless you want to zero out the margins of the container element for these paragraphs as well, you shouldn't need to zero out the margins of the first and last p elements specifically. Here's a fiddle to illustrate.

how to select even rows and exclude last column

You can target the tr elements that are even with tr:nth-child(even) followed by excluding the last td td:not(:last-child), the selector becomes tr:nth-child(even) td:not(:last-child)

tr:nth-child(even) td:not(:last-child) {  background-color: #f00;}

/** only for demo purposes **/
table,tr,td { border: 1px solid #000;}
td { padding: 8px;}
<table>  <tr>    <td>1</td>    <td>name</td>    <td>age</td>    <td>country</td>    <td id="rmv"><button>remove</button></td>  </tr>  <tr>    <td>1</td>    <td>name</td>    <td>age</td>    <td>country</td>    <td id="rmv"><button>remove</button></td>  </tr>  <tr>    <td>1</td>    <td>name</td>    <td>age</td>    <td>country</td>    <td id="rmv"><button>remove</button></td>  </tr>  <tr>    <td>1</td>    <td>name</td>    <td>age</td>    <td>country</td>    <td id="rmv"><button>remove</button></td>  </tr></table>

Issue with CSS 'everything except last' selector

Here you go - you pretty much had it, just make sure to use the :last-of-type pseudoclass