html - Last child not working as expected with p tag -
i have issue using :last-child
class p
tag, works fine other classed p
tags, here's code:
<div class="port-container"> <div class="header"><h1>portfolio</h1></div> <p class="header" ref="who">who i?</p> <p class="info" ref="who">...</p> <p class="header" ref="what">what do?</p> <p class="info" ref="what">...</p> <p class="header" ref="projects">current projects?</p> <p class="info" ref="projects">...</p> <p class="header" ref="conntact">contact me</p> <p class="info" ref="conntact">...</p> </div> <img class="bg-button pull-center" bg-toggle="false" src="./assets/icon-bg_white.png" title="toggle background" />
my css:
.pull-center { position:absolute; margin:auto auto; top:0;bottom:0; left:0;right:0; } div.port-container { width:975px; height:auto; overflow:auto; margin:auto auto; } div.port-container > .bg-toggle { background-color:rgba(44,62,80,0.25); border-color:rgba(0,0,0,0.5) !important; } div.port-container > div.header { height:200px; line-height:200px; border:solid 1px #fff; border-top-left-radius:5px; border-top-right-radius:5px; text-align:center; color:#fff; } div.port-container > p.header { padding:10px; border-bottom:solid 1px #fff; border-left:solid 1px #fff; border-right:solid 1px #fff; color:#fff; cursor:pointer; } div.port-container > p.header:last-child { /*<----- issue */ border-bottom-left-radius:5px; border-bottom-right-radius:5px; } div.port-container > p.header.active { border-bottom-left-radius:0px; border-bottom-right-radius:0px; } div.port-container > p.info { padding:10px; border:solid 1px #fff; border-top:none; display:none; color:#fff; } div.port-container > p.info:last-child { /*<----- works fine */ border-bottom-left-radius:5px; border-bottom-right-radius:5px; } img.bg-button { width:32px; height:32px; top:auto;left:auto; }
note: ref attribute used in jquery
tl;dr:
this works fine:
div.port-container > p.info:last-child { border-bottom-left-radius:5px; border-bottom-right-radius:5px; }
but doesn't:
div.port-container > p.header:last-child { border-bottom-left-radius:5px; border-bottom-right-radius:5px; }
p.info:last-child
matches p.info
elements last children of parent.
in markup, p.header
not last children of parent while p.header
matches various elements, p.header:last-child
match none.
unfortunately, there no :last-of-its-class
selector. matching not possible unless make assumptions html structure. made one:
p.header:nth-last-child(2) { }
it matches p.header
elements second last children of parent. note requires css3 selectors support.
p { background: #ccc; } p.info:last-child { background: #fc0; } p.header:nth-last-child(2) { background: #fc6; }
<div class="port-container"> <div class="header"><h1>portfolio</h1></div> <p class="header" ref="who">who i?</p> <p class="info" ref="who">...</p> <p class="header" ref="what">what do?</p> <p class="info" ref="what">...</p> <p class="header" ref="projects">current projects?</p> <p class="info" ref="projects">...</p> <p class="header" ref="conntact">contact me</p> <p class="info" ref="conntact">...</p> </div>
Comments
Post a Comment