- This topic is empty.
-
AuthorPosts
-
November 21, 2012 at 10:59 am #40914
alexmccabe
ParticipantNormally I don’t have any issues with CSS, however this one has me completely stumped!
If you take a look at [this pen](http://codepen.io/alexmccabe/pen/Esurd “this pen”), you can see that there are 5 . hr div classes. In the CSS the last one should be hidden, but it won’t. I set the colour to red just to see if it was being targeted at all. And it is not.
Anyone have any ideas? Would be much appreciated. Causing me actual issues in my project. I can target it using nth-child(n) but I don’t know how many children there will be. Bloody odd.
first-child doesn’t work either.
November 21, 2012 at 11:03 am #115065Watson90
MemberNovember 21, 2012 at 11:04 am #115066Paulie_D
MemberYou’re using the the wrong pseudo class
.hr:last-of-type
EDIT…Aw, SNAP
Browser support ain’t great though.
November 21, 2012 at 11:06 am #115069Watson90
MemberI think last child only works if it has a parent element such as an unordered list with 5 list items, if you wanted to target the last item, you would then use last-child.
November 21, 2012 at 11:07 am #115070Paulie_D
MemberBecause each item is not a child of anything.
EDIT: FFS….SNAP again.
November 21, 2012 at 11:08 am #115071Paulie_D
MemberOK….here’s something…why create a div with that class instead of just styling your ‘hr’ tag?
CSS Tricks does.
See:
November 21, 2012 at 11:13 am #115073Watson90
MemberLol :)
Yeah I’d agree with @Paulie_D on this one, its just much more simple and a lot less markup (which is always a good thing)
November 21, 2012 at 11:18 am #115076Watson90
MemberShouldn’t your css be as simple as;
border: 0px none;
height: 1px;
background: -moz-linear-gradient(left center , transparent, rgba(0, 0, 0, 0.5), transparent) repeat scroll 0% 0% transparent;
margin: 35px 0px 33px;just like Chris uses…
November 21, 2012 at 11:22 am #115079Paulie_D
MemberI think he was just using -moz as an example.
It’s understood that we would target respective browsers using the correct prefix.
…and who gives a flying ‘fig’ about IE? LOL
November 21, 2012 at 11:35 am #115082Paulie_D
MemberYou mean like this?
November 21, 2012 at 11:56 am #115084Paulie_D
MemberAs for why your previous version failed, I am having no luck.
It could be a specificity issue but I can’t get it to function ‘as expected’ regardless of how detailed I get.
November 21, 2012 at 2:51 pm #115091wolfcry911
Participantit fails because it’s not the last child
November 21, 2012 at 2:56 pm #115092Paulie_D
Member@wolfcry911… yeah, we’re past that and on to why last-of-type isn’t working here.
November 21, 2012 at 4:36 pm #115098wolfcry911
Participantwell the pen he links to asking why it still fails uses last-child
last-of-type is going to fail as well, because type refers to the element (not a specific classed element).
November 21, 2012 at 5:30 pm #115101Paulie_D
Member>last-of-type is going to fail as well, because type refers to the element (not a specific classed element).
Boom…and there’s the answer we were looking for. :)
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.