picostyle icon indicating copy to clipboard operation
picostyle copied to clipboard

Difficulty to make a component with complex CSS selectors

Open matschik opened this issue 7 years ago • 2 comments

Hi ! Thanks a lot for this lightweight library !

I'm experiencing difficulties with this piece of CSS to a Picostyle wrap component. Anybody got a solution for this complex piece of CSS ?


/* Dynamic columns */
/* one column */
.dcolumn:first-child:nth-last-child(1) {
  float: left;
  width: 100%;
}

/* two columns */
.dcolumn:first-child:nth-last-child(2),
.dcolumn:first-child:nth-last-child(2) ~ .dcolumn {
  float: left;
  width: 50%;
}

/* three columns */
.dcolumn:first-child:nth-last-child(3),
.dcolumn:first-child:nth-last-child(3) ~ .dcolumn {
  float: left;
  width: 33.3333%;
}

/* four columns */
.dcolumn:first-child:nth-last-child(4),
.dcolumn:first-child:nth-last-child(4) ~ .dcolumn {
  float: left;
  width: 25%;
}

matschik avatar Oct 27 '18 15:10 matschik

Thank you for using picostyle! Now, we can't refer components' class name in the component, so we can use the following selector.

.dcolumn:first-child:nth-last-child(2) ~ .dcolumn {}
const DynamicColumn = style("div")({
  // some styles

  "first-child:nth-last-child(2)": {
    float: left;
    width: 50%;
  },
  "first-child:nth-last-child(2) ~ .dcolumn": { // we can't know `.dcolumn` (this component's class name)
    float: left;
    width: 50%;
  }
})

I'll try to support it.

morishxt avatar Nov 05 '18 05:11 morishxt

Thank you very much for your confirmation ! Anyway these styles are convenient to be declared in global CSS scope.

matschik avatar Nov 05 '18 22:11 matschik