Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
sibling selector with :before doesn't work in styled-component?

How to use this

li+li:before {
  padding: 8px;
  color: black;
  content: "/\00a0";
}

in styled-component? I tried to convert this https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_breadcrumbs

to styled-component but it's not working.

https://codesandbox.io/s/recursing-pasteur-mkmyh?file=/src/App.js

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The content of the content seems to be the culprit. The rest of the code is fine.

Instead of /\00a0 it should be /\\00a0. It seems to be a styled-components specific issue.

Here's a short quote as an explanation, the source has more in depth discussion.

Basically because you write CSS in JS you have to escape twice - once for JS parser and once for CSS one.

Source/GitHub

Full working code:

import styled from "styled-components";

export default function Namaste() {
  return (
    <UL>
      <li>
        <a href="/#">Home</a>
      </li>
      <li>
        <a href="/#">Pictures</a>
      </li>
      <li>
        <a href="/#">Summer 15</a>
      </li>
      <li>Italy</li>
    </UL>
  );
}

const UL = styled.ul`
  padding: 10px 16px;
  list-style: none;
  background-color: #eee;

  li {
    display: inline;
    font-size: 18px;
    color: red;
  }
  li + li:before {
    padding: 8px;
    color: black;
    content: "/\\00a0";
  }
  li a {
    color: #0275d8;
    text-decoration: none;
  }
`;

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!