Nullify border-bottom on last child


#1
<div class="wrap">
	<div class="headlines"></div>	
	<div class="headlines"></div>	
	<div class="headlines"></div>	
	<div class="headlines"></div>	
	<div class="headlines"></div>			
</div>

border-bottom set on the class .headlines - But how should I nullify the border-bottom on the last headline div i.e. last child of wrap div?

Above is a hypothetical situation. The number of headlines DIV’s are not fixed.


#2

Try

.headlines:last-child {
     border-bottom: none;
}

#3

Already tried. Doesn’t work.


#4

headlines div are the child of wrap.


#5

Yes, It does

<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Test Page</title>
<style>

.headlines {
  min-height:2em;
  margin:1em;
  background:lightblue;
  border-bottom:1px solid;
}
.headlines:last-child {
  border-bottom:none;
  background:yellow;
}
</style>

</head>
<body>

<div class="wrap">
  <div class="headlines"></div>
  <div class="headlines"></div>
  <div class="headlines"></div>
  <div class="headlines"></div>
  <div class="headlines"></div>
</div>

</body>
</html>

last-child


#6

In my case why it is not working.


#7

Because the last child of ‘main’ is a div without the ‘headlines’ class. Wrap your headlines in their own div, and the CSS will work.

The example on the MDN page for last-child may help explain the concept.


#8

Alternatively, based on the HTML you have presented there,
article:last-of-type would also select the correct element.


#10

Yes! Yes! Yes! Yes! Yes!


#11

Do you know why :last-child did not work and :last-of-type works?


#12

Yes, because last headline was not actually the last child.

it worked because it was tragetting the last of article type(last article child).

Do I pass the understanding test?


#13

Be careful with that last sentence.

It’s targetting the last article within the container.

<div>
    <article>1</article>
    <article>2</article>
</div>
<div>
    <article>3</article>
    <article>4</article>
</div>

In this instance, article:last-of-type will target both article 2 and 4.


#14

Yes, I am aware last of article in the wrap div.


#15

Yes, Yes. The point is clear to me. Thank you for extending the support to eliminate any possibility of any doubt.


#16

Well done smile


#17

Your appreciation is like pulitzer prize for me. You are mostly skeptic that I am lazy and do not work hard and immediately come here to seek help. :wink:

Off Topic →
Initially, I feel annoyed by you. I thought you always bully me when others are helping me. But later I realized you are my well-wisher. You knew that I am more capable, but I am not giving full 100% in learning concepts but looking for a slipshod remedy and immediate gratifications.

Generally, People and society yell at you. Who in this world care for someone else that he should excel in life. Thank you so much for thinking for me and taking the pain to guide me so that I should truly excel in life.


#18

On the same link that I shared above I am struggling to align “+” sign in vertical middle. Please help me to move in forward direction.

Please open the image in new browser.


#19

Use flex as that’s what it’s good at.

e.g.

.load-more {display:flex;justify-content:center;}
.load-more a{display:flex;align-items:center;padding:10px 40px;}
.load-more span{margin-left:.2em;}

#20

I know you have it sorted out now.
Next time post the correct html in your first post to avoid confusion. :slightly_smiling_face:

I was working with the html you gave in your first post.


#21

Sure.