1

I'm trying to make an underline effect for the li tag using the ::after psuedo-element under the react-jss framework. However, it's not working in the page.

Here's the whole example in code sandbox: https://codesandbox.io/s/confident-taussig-ecif2

And part of the code:

          <ul>
            <li>
              <a href="">Page1</a>
            </li>
            <li>
              <a href="">Page2</a>
            </li>
            <li>
              <a href="">Page3</a>
            </li>
            <li>
              <a href="">Page4</a>
            </li>
          </ul>

and the styling in react-jss:

"& > ul": {
    display: "flex",
    height: "100%",
    flexDirection: "row",
    position: "relative",

    "& li": {
      display: "flex",
      listStyle: "none",
      justifyContent: "center",
      alignItems: "center",
      overflow: "visible"
    },

    "& > li": {
      width: "80px",
      height: "100%",
      padding: "0 10px",
      position: "relative",

      "& a": {
        color: "black",
        textDecoration: "none"
      },

      "&:after": {
        content: "",
        position: "absolute",
        bottom: 0,
        left: 0,
        display: "block",
        width: "80px",
        height: "1px",
        backgroundColor: "black",
        zIndex: "99"
      }
    }
  }

OK, I've been tracking down this issue, and I saw the solution in Can't target :before Pseudo selector in JSS, and it seems to be the "content" property that is blocking the :after pseudo-element from showing itself.

The answer in that post said that, and I quote,

The content should be a string enclosed in double quotes which in turn should be enclosed in single quotes.

Why is this strange syntax? Is is just in react-jss or it's a common thing is CSS/SCSS?

Gary Yuan
  • 33
  • 2
  • 9
  • not only react. Default js does not have pesudo element property, so better do with css – prasanth Jan 23 '21 at 09:13
  • Does this answer your question? [Pseudo after element css properties are not working in jquery](https://stackoverflow.com/questions/56231749/pseudo-after-element-css-properties-are-not-working-in-jquery) – prasanth Jan 23 '21 at 09:13
  • @prasanth In my understanding, react-jss just transfer the style file written in .js file to .css/.scss file and then associate them with react component. Thus, eventually it's still a css thing. – Gary Yuan Jan 24 '21 at 06:13
  • yes.. check this https://cssinjs.org/repl. – prasanth Jan 24 '21 at 08:36

0 Answers0