I am trying to target the after pseudo selector of an element on my page. I am trying out JSS for this project and am a huge fan so far, but still very new to it. I am having troubles selecting the :after selected with JSS. Is this possible because I thought it was when reading the docs.
This is my mark up:
<Link to="about" className={classes.link}>About</Link>
and my JSS looks like this:
link: { position: 'relative', fontFamily: fonts.family.primary '&:before': { content: ' ', position: 'absolute', bottom: 0, left: 50, width: '100%', height: '1rem', display: 'block', background:styles.colors.white } }
if anyone who is familiar with JSS could help, that would be great!
CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
Pseudo-classes are CSS classes used to define the state of an element. They target elements that can't be targeted with combinators or simple selectors like id or class. They are used to select elements based on their attributes, states, and relative position.
You can still chain pseudoselectors. For example, a:focus:hover works just fine to apply styles only if the element is focused AND hovered. See this link for a demonstration. It works fine (in Chrome, at least); click in the demo area, press tab to focus the link, then hover it to see it become bolded.
What you did is right. Except for 2 things:
1) Syntax error: You're missing a comma after the entry fontFamily: fonts.family.primary
2) The content should be a string enclosed in double quotes which in turn should be enclosed in single quotes. So, an empty content would be content: '""',
So just try the following:
link: { position: 'relative', fontFamily: fonts.family.primary, '&:before': { content: '""', position: 'absolute', bottom: 0, left: 50, width: '100%', height: '1rem', display: 'block', background:styles.colors.white } }
Seems like a good place to add this too...
If you want to add a symbol (like an "
) to the content:
then this did the trick for me:
// symbol const $quoteSym = '"'; // jss class quote: { color: 'white', position: 'relative', padding: '2rem', '&:before': { display: 'inline-block', content: `'${$quoteSym}'`, }, },
Looks a little hacky but the encapsulation method/order, with regards to what type of quotes you use, seems to make a difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With