Named CSS grid lines with SCSS

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 12:28:37

问题


I'm experimenting with the new CSS Grid Layout system in codepen.io. It has an interesting feature called named grid lines that allows defining custom names for the grid lines between the columns and rows. Unfortunately I can't seem to get the feature to work because SCSS doesn't approve of the [line-name] syntax.

#container.named {
  grid-template-columns: [main-start] 100px [content-start] 1fr [content-end] 100px [main-end]; // Will not pass SCSS validation :(

  .one {
    grid-column: content-start / content-end;
  }
}

The code above should create a CSS grid that has two 100px wide columns on the sides with a column that fills the rest of the element's width in the center. This part works fine. I then try to give the grid lines custom names and place the .one element in the middle column but Codepen's SCSS preprocessor (as well as all the other compilers I've tried) refuses to compile the whole thing, saying Invalid CSS after "...plate-columns: ": expected expression (e.g. 1px, bold), was "[main-start] 10..."

Is there some way to force SCSS to compile this style as-is without parsing it (or express this in another way that compiles) or will I have to rewrite my experiment with regular CSS?


回答1:


Try putting whole your CSS line to string:

$gridTplCols: "[main-start] 100px [content-start] 1fr [content-end] 100px [main-end]";

grid-template-columns: #{$gridTplCols};


来源:https://stackoverflow.com/questions/43206860/named-css-grid-lines-with-scss

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!