grmpyprogrammer,
@grmpyprogrammer@phpc.social avatar

#CSS peeps — is there a way to build a selector that finds (to use an example) ‘h3.post a’ or ‘h3.post-title a’

ryan,
@ryan@hachyderm.io avatar

@grmpyprogrammer If you're looking for a selector that affects an anchor in either of those classes, the laborious way:

h3.post a, h3.post-title a {...}

grmpyprogrammer,
@grmpyprogrammer@phpc.social avatar

@ryan One if my co-workers suggested that too, was just looking to find out all the different ways I could match stuff. Appreciate the help!

ryan,
@ryan@hachyderm.io avatar

@grmpyprogrammer any time! I'd personally go the :is() pseudo-selector route.

Expresses the intent, is easier to maintain. The only surprise might be additional specificity, but if that's a problem (likely isn't) you can use :where(). Happy styling!

derickr,
@derickr@phpc.social avatar

@grmpyprogrammer Are "post" or "post-title" supported to be classes on the <h3>? Because in that case, what you wrote should work.

grmpyprogrammer,
@grmpyprogrammer@phpc.social avatar

@derickr Yeah, they are classes of the h3

timwolla,
@timwolla@phpc.social avatar

@grmpyprogrammer Those two are already valid CSS selectors, so I don't understand the question.

phoopee3,

@grmpyprogrammer h1[class^=post] a should do it for you - https://codepen.io/phoopee3/pen/KKreZGL

cornflour,

@grmpyprogrammer I am a bit confused, aren't h3.post a and h3.post-title a both css selectors that find those (an anchor tag which is the child of an h3 with the class post or an h3 with class post-title)? Can you clarify a bit on what you're looking to do?

grmpyprogrammer,
@grmpyprogrammer@phpc.social avatar

@cornflour I don’t know much about CSS selectors so I was wondering how I write one that matches an anchor inside an h3 with the class post or post-title.

cornflour,

@grmpyprogrammer oh so you want a selector to match either of those right? In that case @ryan already said the best answer I think, but h3.post a, h3.post-title a {} or h3:is(.post, .post-title) a {} both should work, with the latter being the more modern approach

vga256,
@vga256@dialup.cafe avatar
grmpyprogrammer,
@grmpyprogrammer@phpc.social avatar

@vga256 Thanks for the link

vga256,
@vga256@dialup.cafe avatar

@grmpyprogrammer good luck!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • CSS
  • DreamBathrooms
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • GTA5RPClips
  • Durango
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • tacticalgear
  • JUstTest
  • osvaldo12
  • tester
  • cubers
  • cisconetworking
  • mdbf
  • ethstaker
  • modclub
  • Leos
  • anitta
  • normalnudes
  • megavids
  • provamag3
  • lostlight
  • All magazines