question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can i pass props to pseudo element?

See original GitHub issue

Description:

I want to pass props to the after element, But i have an error… I found all documents, but i cant solve my issue

interface Time {
  time: number
}

const Bubble = styled<'div', Time>('div')`
  display: inline-block;
  position: relative;
  background: rgba(104, 127, 209, 0.5);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 5px;
  padding: 9px;
  margin-top: 9px;
  line-height: 15px;

  &:first-of-type {
    &:before {
      content: '';
      position: absolute;
      top: 20%;
      left: -9px;
      width: 0;
      height: 0;
      border-top: 0px solid transparent;
      border-radius: 1px 0 0 0;
      border-bottom: 12px solid transparent;
      border-right: 9px solid rgba(104, 127, 209, 0.5);
    }
  }

  &:last-of-type {
    &:after {
      content: ${props => `${props.width}%`};
      position: absolute;
      left: 100%;
    }
  }
`

image

i cant find after element.

Documentation links:

Can I refer to this document?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
SoYoung210commented, Mar 31, 2020

@kud
I closed the issue because it was my mistake. 😅 Here’s example.

&:last-of-type {
    &:after {
-      content: ${props => `${props.width}%`};
+      content: '${props =>  `${props.width}`}';
      position: absolute;
      left: 100%;
      font-size: 10px;
      margin-left: 8px;
      bottom: 3%;
    }
  }
1reaction
kudcommented, Mar 31, 2020

Yeah I was trying this:

const ColourSquare = styled.div`
  width: 4rem;
  height: 4rem;
  display: inline-block;
  margin-right: 1rem;
  margin-bottom: 1rem;

  background-color: ${({ colour }) => colour};

  &:before {
    content: ${({ colour }) => `${colour}`};
    display: block;
  }
`

Apparently the ' were missing. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Styled Components and passing props to psedo ...
I have the follwing styled component, I am trying to pass a prop to it and use it in a pseudo element selector,...
Read more >
Pseudo-elements - CSS: Cascading Style Sheets | MDN
A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s).
Read more >
How to make reusable components with pseudo-selectors
By default, it uses the string "button" as its type — but by passing an as prop, you can set that to "a"...
Read more >
API Reference - styled-components
If you want to prevent props meant to be consumed by styled components from being passed to the underlying React node or rendered...
Read more >
PseudoBox - Chakra UI | Design System built with React
For example, to style &:hover , use the _hover prop and pass the style props. We use the underscore _ notation to visually...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found