Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Nesting SCSS pseudo selectors

I have this structure of pseudo elements:

&::before {
  content: '';
  position: absolute;
  height: 100%;
  width: 1px;
  background: ${(props) => props.theme.colors.link};
  right: 6px;
}
&:first-child:before {
   content: '';
   position: absolute;
   height: 50%;
   width: 1px;
   background: ${(props) => props.theme.colors.link};
   right: 6px;
   bottom: 0;
 }
&:last-child:before {
  content: '';
  position: absolute;
  height: 50%;
  width: 1px;
  background: ${(props) => props.theme.colors.link};
  right: 6px;
  top: 0;
}

As you can see, in first-child and last-child I only overwrite 2 properties, so, it seems to make it nested in &::before, but I can’t. Also, on Internet, I haven’t found, if it’s possible.

Everything works just find, I just want to know, if there is possibility to make this code look prettier.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this

div {
  &::before{
    content: '';
    position: absolute;
    height: 100%;
    width: 1px;
    background: ${(props) => props.theme.colors.link};
    right: 6px;
  }
  &:first-child:before {
      height: 50%;
      bottom: 0;
  }
  &:last-child:before {
      height: 50%;
      top: 0;
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading