Skip to content

how to target children ? #157

Closed Answered by ben-rogerson
vital-tech-results asked this question in Q&A
Discussion options

You must be logged in to vote

Hey there, I recommend using benface's typography plugin to target the container children with the richtext class.

If you feel like doing this yourself, then you could make your own RichText wrapper component:

// components/RichText.js
import tw, { styled, css } from 'twin.macro'

const BaseStyles = tw`text-left p-8 md:text-left text-sm md:text-base lg:text-lg font-medium leading-relaxed text-secondary-100 mt-4`
const ChildrenStyles = css({
  div: tw`bg-black`,
  span: tw`bg-red-400`,
  // and you can include advanced css selectors
  '> img + img': tw`mt-5`,
  'img + &': tw`mt-10`,
})

const RichText = styled.div(() => [BaseStyles, ChildrenStyles])

export default RichText
// pages/About.js

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@vital-tech-results
Comment options

@vital-tech-results
Comment options

@vital-tech-results
Comment options

Answer selected by ben-rogerson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants