sass icon indicating copy to clipboard operation
sass copied to clipboard

Shorthand for declaring multiple CSS properties like CoffeeScript variables

Open chriseppstein opened this issue 14 years ago • 59 comments

I have become fond of CoffeeScript's ability to declare variables that have the same value in this manner:

someVariable: anotherVariable: "someValue"

I would like the ability to declare CSS properties in SASS/SCSS like this:

width: height: 10px;

and then the output would be:

width: 10px;
height: 10px;

Originally filed by @deleteme

chriseppstein avatar Jun 09 '11 05:06 chriseppstein

It's an interesting idea, but I think I prefer:

width, height: 10px;

as a syntax. I find myself needing this every once and a while usually when I need to set margin-left and margin-right to the same value without setting margin-top and margin-bottom via the compound property.

chriseppstein avatar Jun 09 '11 05:06 chriseppstein

I don't know why I referenced CoffeeScript. JavaScript lets you do the same thing, but it uses an equals sign.

For sass and scss, I would prefer a colon because it is the normal assignment character.

deleteme avatar Jun 09 '11 06:06 deleteme

The colon syntax allows for easier copy and paste than using a comma. Also the comma is extra syntax which may be non obvious in situations where attributes use commas too.

chrislloyd avatar Jul 13 '11 14:07 chrislloyd

@chrislloyd, the parity with selectors makes the comma very obvious imo.

chriseppstein avatar Jul 13 '11 16:07 chriseppstein

Even though it does sound like a cool feature; I believe that we could benefit more of having an alias to @include for .scss syntax like proposed on issue #129 , with all the mixin functionality you can easily make something like:


@mixin size($size) {
  @if length($size) == 2 {
    @if "#{nth($size, 1)}" != "0" { width:nth($size, 1); }
    @if "#{nth($size, 2)}" != "0" { height:nth($size, 2); }
  } @else {
    width:nth($size, 1);
    height:nth($size, 1);
  }
}

Then:

+size(100px)

Which is shorter than width:height:etc

MarioRicalde avatar Jul 15 '11 20:07 MarioRicalde

I really like this.

I think that using the "comma" syntax is better, due to it having a closer similarity due declaring multiple styles in CSS spec, it would make sense for variables too.

dfischer avatar Jul 15 '11 20:07 dfischer

@kuroir the decision to not have a shorthand syntax in .scss files has been discussed enough. I understand the convenience, but it's not enough to warrant the parsing violations.

chriseppstein avatar Jul 15 '11 20:07 chriseppstein

/sigh I won't hijack this thread. I'll send you a message.

MarioRicalde avatar Jul 15 '11 20:07 MarioRicalde

An elaboration upon my original idea would be that the value of the properties could be used like variables, local to the block.

Lets see what that would look like:

With colons:

#foo, .bar
  width: height: 10px
  margin: width / 2

With commas:

#foo, .bar
  width, height: 10px
  margin: width / 2

Renders:

#foo, .bar {
  height: 10px;
  width: 10px;
  margin: 5px;
}

My issue with using commas for multiple assignment, is that meaning of the comma would change, or, just grow to include more. A comma is already used in selectors, and I believe it's already in use as a way to separate arguments to helpers/methods.

A colon doesn't require any change of meaning. Think of it as a JavaScript equals sign. It would read, "width equals height equals 10px".

A comma reads, "width and height equals 10px".

deleteme avatar Jul 15 '11 20:07 deleteme

@chriseppstein Ah, didn't see your response before I posted. I didn't know this was already discussed somewhere else. If you have already come to some decision not to do this, then you could go ahead and close this.

deleteme avatar Jul 15 '11 20:07 deleteme

@deleteme he was talking to me, regarding the + as @include alias on .scss syntax.

MarioRicalde avatar Jul 15 '11 21:07 MarioRicalde

Just adding my +1 from issue #197 here, specifically for the comma-separated style (width, height: 10px;).

jleclanche avatar Oct 17 '11 17:10 jleclanche

I particularly like @deleteme's last idea of referencing other local properties as variables. I need this all the time. I sometimes end up having to declare multiple variables in a selector, where non would be required if this feature were available, and it looks quite ugly.

miracle2k avatar Jan 14 '12 16:01 miracle2k

@miracle2k I think that's the subject of a different issue.

jleclanche avatar Jan 14 '12 16:01 jleclanche

Being able to access local properties would open a whole world of mixins, I'm really in favor of this.

Anahkiasen avatar Feb 29 '12 08:02 Anahkiasen

Chris just pointed me to this, I'd like the comma dilem method, would be cool!

cjcheshire avatar Mar 16 '12 17:03 cjcheshire

+1

kuraga avatar Sep 06 '12 17:09 kuraga

+1

battaglr avatar Sep 06 '12 17:09 battaglr

+1 I am for a comma separated list of properties as the colon separated list makes me think the following properties are nested in the previous ones. Comas follow the rules already defined for selectors.

scottkellum avatar Sep 19 '12 01:09 scottkellum

+1

headbandno2 avatar Nov 09 '12 23:11 headbandno2

+1

Any update on this?

I prefer the comma-based syntax. Would be really cool to be able to do this:

margin: {
  left, right: 20px;
}

shkm avatar Aug 29 '13 14:08 shkm

+1 on the comma based syntax

Anahkiasen avatar Sep 10 '13 15:09 Anahkiasen

  • 1

On 10 September 2013 16:16, Maxime Fabre [email protected] wrote:

+1 on the comma based syntax

— Reply to this email directly or view it on GitHubhttps://github.com/nex3/sass/issues/109#issuecomment-24168386 .

cjcheshire avatar Sep 11 '13 15:09 cjcheshire

+1 from me as well, the typical case for me being:

height, line-height: 50px;

zikkoerik avatar Dec 03 '13 12:12 zikkoerik

I find myself doing this all the time:

$var: value;
foo: $var;
bar: $value;

It's utterly annoying. So bump.

lolmaus avatar Jan 06 '14 08:01 lolmaus

Bump, expressing support for a, b: c

ddevault avatar Jan 07 '14 23:01 ddevault

+1. Also behind the comma-based syntax. Really missing this in my day-to-day development.

omervk avatar Jan 20 '14 14:01 omervk

+1, why is this closed?

felippenardi avatar May 13 '14 12:05 felippenardi

It ain't closed. But nobody is working on it either.

lolmaus avatar May 13 '14 12:05 lolmaus

Haven't been in the Sass issue queue for a while; so much work going on! Sass ++.

I really like the comma syntax. top, left, bottom, right: 0; would be a big timesaver for me.

The colon syntax might be harder to implement because we have some properties that allow other properties inside them. You'd have to look ahead to decide whether transition: translateY... is going to be a multiple assignment or a simple css rule.

robwierzbowski avatar May 15 '14 03:05 robwierzbowski