How to select last child of tspecific class in css [duplicate]Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?How to horizontally center a <div>?How to change an element's class with JavaScript?How do I give text or an image a transparent background using CSS?How to disable text selection highlightingIs there a CSS parent selector?Change an HTML5 input's placeholder color with CSSCSS selector for first element with classHow to disable resizable property of textarea?How do I vertically center text with CSS?Is it possible to apply CSS to half of a character?
Supervisor wants me to support a diploma-thesis SW tool after I graduated
How does a changeling's Divergent Persona affect bard spells cast using musical instruments?
How do you say "to hell with everything" in French?
When does order matter in probability?
How can faith be maintained in a world of living gods?
The Green Glass Door, Revisited
Why can't some airports handle heavy aircraft while others do it easily (same runway length)?
I multiply the source, you (probably) multiply the output!
How can Schrödinger's cat be both dead and alive?
Friend is very nitpicky about side comments I don't intend to be taken too seriously
Are professors obligated to accept supervisory role? If not, how does it work?
Can you pop microwave popcorn on a stove?
Is future tense in English really a myth?
Is there a way to deal with desistance in a off-chain game?
Owner keeps cutting corners and poaching workers for his other company
Methods and Feasibility of Antimatter Mining?
Infinitely many primes
How strong is aircraft-grade spruce?
antimatter annihilation in stars
How do Scrum teams manage their dependencies on other teams?
How should Thaumaturgy's "three times as loud as normal" be interpreted?
2 load centers under 1 meter: do you need bonding and main breakers at both?
The pirate treasure of Leatherback Atoll
Word for something that used to be popular but not anymore
How to select last child of tspecific class in css [duplicate]
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?How to horizontally center a <div>?How to change an element's class with JavaScript?How do I give text or an image a transparent background using CSS?How to disable text selection highlightingIs there a CSS parent selector?Change an HTML5 input's placeholder color with CSSCSS selector for first element with classHow to disable resizable property of textarea?How do I vertically center text with CSS?Is it possible to apply CSS to half of a character?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
5 answers
Need to apply CSS to div with class name test except last div having class test.
in below case -
first 2 div.test should have margin but 3rd div.test should not.
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph</div>
</div>
div.test-1 should not apply anything
html css
marked as duplicate by Paulie_D
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 11:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
5 answers
Need to apply CSS to div with class name test except last div having class test.
in below case -
first 2 div.test should have margin but 3rd div.test should not.
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph</div>
</div>
div.test-1 should not apply anything
html css
marked as duplicate by Paulie_D
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 11:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
1
:last-of-type
– Pranav C Balan
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25
add a comment |
This question already has an answer here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
5 answers
Need to apply CSS to div with class name test except last div having class test.
in below case -
first 2 div.test should have margin but 3rd div.test should not.
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph</div>
</div>
div.test-1 should not apply anything
html css
This question already has an answer here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
5 answers
Need to apply CSS to div with class name test except last div having class test.
in below case -
first 2 div.test should have margin but 3rd div.test should not.
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph</div>
</div>
div.test-1 should not apply anything
This question already has an answer here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
5 answers
html css
html css
edited Mar 28 at 7:54
Usman Maqbool
2,2637 gold badges22 silver badges35 bronze badges
2,2637 gold badges22 silver badges35 bronze badges
asked Mar 28 at 7:17
VishuVishu
4703 gold badges7 silver badges15 bronze badges
4703 gold badges7 silver badges15 bronze badges
marked as duplicate by Paulie_D
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 11:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Paulie_D
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 11:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Paulie_D
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 11:20
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
1
:last-of-type
– Pranav C Balan
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25
add a comment |
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
1
:last-of-type
– Pranav C Balan
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
1
1
:last-of-type– Pranav C Balan
Mar 28 at 7:19
:last-of-type– Pranav C Balan
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25
add a comment |
3 Answers
3
active
oldest
votes
Use .test:nth-last-child(-n+2) to select the last child of .test
.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>add a comment |
Try This
Example using a suggestion from @ לבני מלכה
.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
To select specific child, you can use nth-child(number) property:
div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use .test:nth-last-child(-n+2) to select the last child of .test
.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>add a comment |
Use .test:nth-last-child(-n+2) to select the last child of .test
.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>add a comment |
Use .test:nth-last-child(-n+2) to select the last child of .test
.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>Use .test:nth-last-child(-n+2) to select the last child of .test
.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>.test:nth-last-child(-n+2)
color:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The fourth paragraph.</div>
</div>answered Mar 28 at 7:32
לבני מלכהלבני מלכה
12k1 gold badge11 silver badges30 bronze badges
12k1 gold badge11 silver badges30 bronze badges
add a comment |
add a comment |
Try This
Example using a suggestion from @ לבני מלכה
.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
Try This
Example using a suggestion from @ לבני מלכה
.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
Try This
Example using a suggestion from @ לבני מלכה
.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>Try This
Example using a suggestion from @ לבני מלכה
.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>.parent .test:not(:nth-child(4))
background:red;
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>edited Mar 28 at 7:53
Mister Jojo
2,5342 gold badges2 silver badges22 bronze badges
2,5342 gold badges2 silver badges22 bronze badges
answered Mar 28 at 7:46
Syed FurqanSyed Furqan
105 bronze badges
105 bronze badges
add a comment |
add a comment |
To select specific child, you can use nth-child(number) property:
div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
To select specific child, you can use nth-child(number) property:
div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>add a comment |
To select specific child, you can use nth-child(number) property:
div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>To select specific child, you can use nth-child(number) property:
div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div> div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div> div:nth-child(2)
color:red
<div class="parent">
<div class="test">
<div>The first paragraph.</div>
</div>
<div class="test">The second paragraph.</div>
<div class="test">The third paragraph.</div>
<div class="test">The fourth paragraph.</div>
<div class="test-1">The firth paragraph.</div>
</div>edited Mar 28 at 10:59
Mister Jojo
2,5342 gold badges2 silver badges22 bronze badges
2,5342 gold badges2 silver badges22 bronze badges
answered Mar 28 at 7:34
JiyaJiya
14 bronze badges
14 bronze badges
add a comment |
add a comment |
By index of child:w3schools.com/cssref/sel_nth-child.asp
– לבני מלכה
Mar 28 at 7:18
By last child:w3schools.com/csSref/sel_last-child.asp
– לבני מלכה
Mar 28 at 7:18
1
:last-of-type– Pranav C Balan
Mar 28 at 7:19
By particular type:w3schools.com/csSref/sel_nth-of-type.asp
– לבני מלכה
Mar 28 at 7:19
nth-child will not work for me, no of elements are flexible. its just need to select last div.test no matter how may div.test are there. :last-of-type will not work with class(only works with element)
– Vishu
Mar 28 at 7:25