question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Less doesn't compile grid-column forward slash shorthand correctly, outputting incorrect CSS

See original GitHub issue

To reproduce:

// In a .less file, add a rule containing the below property
.some-class {
    grid-column: 1 / -1
}

Current behavior:

The grid-column CSS property (part of the CSS Grid) supports a shorthand form using a forward slash, as shown in the example above, which sets the grid lines a column starts (before the slash) and ends on (after the slash). (See https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column) Less currently doesn’t process this shorthand correctly; Less compiles the example above to grid-column: -1, which sets column to start from line -1.

Expected behavior:

The rule grid-column: 1 / -1 should be not altered during compilation; it is standard CSS. In the example above, the property in the output CSS should appear exactly as it does in the Less source file.

Environment information:

  • less version: 4.1.2
  • nodejs version: v16.13.1
  • operating system: Windows 10 Pro 64-bit

A workaround I have been using for this problem is to escape the property value, so instead of grid-column: 1 / -1, I will write grid-column: ~'1 / -1'.

My theory is that this issue occurs because Less is trying to do a division operation using the numbers of either side of the slash.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iChenLeicommented, Dec 26, 2021

https://github.com/rowanlovejoy/less_test/blob/652ff774b3c98351bdaaf538ae0ab749c05d5d0a/package-lock.json#L8145-L8150

  "snowpack-plugin-less": {
      "version": "1.0.7",
      "resolved": "https://registry.npmjs.org/snowpack-plugin-less/-/snowpack-plugin-less-1.0.7.tgz",
      "integrity": "sha512-cuFVPltfS9nf0EayN0uigoelbGrhZ6DlEAPqnIT4sv2v0mRE+f+06eHfk4J/9wKz/5E2bYsLFXED9hjnf11b4Q==",
      "dev": true,
      "requires": {
          "less": "^3.12.2",
          "tslib": "^2.1.0"
      },
      "dependencies": {

snowpack-plugin-less using less v3 to compile less file, so cause unexpected css output. @rowanlovejoy

BTW: please using vite rather than snowpack, vite is better and actively maintained.

1reaction
rowanlovejoycommented, Dec 26, 2021

@iChenLei Here’s a minimal reproduction repo (or at least as minimal as I know how to do): https://github.com/rowanlovejoy/less_test/tree/main

Inside styles.less, the currently broken code is uncommented; the working code is commented out above it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slashes (`/`) in CSS values when using Less (e.g. in `font ...
The forward slash / character is causing the LESS compiler to divide your font-size by your line-height. You can: Separate your CSS into...
Read more >
CSS Grid in IE: CSS Grid and the New Autoprefixer
Autoprefixer is a tool used for automatically adding browser-specific CSS prefixes to your CSS so that you don't have to.
Read more >
grid-row - CSS: Cascading Style Sheets - MDN Web Docs
The grid-row CSS shorthand property specifies a grid item's size and location within a grid row by contributing a line, a span, or...
Read more >
CSS Values and Units Module Level 3 - W3C
This CSS module describes the common values and units that CSS properties accept and the syntax used for describing them in CSS property ......
Read more >
stylelint | Yarn - Package Manager
has over 170 built-in rules for modern CSS syntax and features ... Fixed: incorrect output by all formatters except for json (#6480 (@ybiquitous)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found