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
.box:not(:last-of-type) > .row { color: red;}
<ul class="box"> <li class="row">One</li> <li class="row">Two</li> <li class="row">Three</li> </ul><ul class="box"> <li class="row">FOur</li> <li class="row">Five</li> <li class="row">Six</li> </ul><ul class="box"> <li class="row">Seven</li> <li class="row">Eight</li> <li class="row">Nine</li> </ul>
Related Topics
How to Make Vertically Rotated Links in HTML
Styling Input Range for Webkit with Pure CSS
How to Change The CSS of Only One Page in Wordpress
How to Use Image as a Table Background in Email
How to Vertically Align Label and Input in Bootstrap 3
CSS: Placing Divs Left/Center/Right Inside Header
Very Different Font Sizes Across Browsers
Why Do Font Squirrel's @Font-Face Definitions Contain Two Src Declarations
CSS Text Replace with Image, Need Hyperlink
How to Scroll Programmatically a Div with Its Own Scrollbars
Nested Rows in Bootstrap 3 Fail to Respect The Grid
Animate Radial-Gradient CSS3: Move from Left to Right
CSS Selector: How to Style Items [1-2][5-6][9-10] etc by Pair
Prevent Contenteditable Mode from Creating <Span> Tags
How to Give a Title Tag a Color and Different Font
Div Moves When I Put Text in It