You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if the extend is inside a media query it should
a) only match other things inside media queries?
b) only match things inside its own media query
c) match everything inside its own media query plus everything not inside another media query, but it should bring that extend inside itself..
is uncontested
2 I am thinking should maybe be (b) in the short term till we figure out if it should match anything else.
Well what would CSS proper do? How would it react? The closer we are to that, the better. Since media queries are theoretically at the root level in regular CSS, that might give some guidance.
EDIT: I have since put a lot more time in thought into the :extend feature and do not really stand by this comment any more. I would like to leave it here for the purpose of conversation, but this should not be a guideline or a suggestion.
I have just run into scenario number 2, and I would like to voice my opinion about it. Let me provide some example code:
After spending much time thinking about this, I don't know that there is really one single elegant solution. The most elegant solution (in my opinion) is for the compiler to copy styles from other media queries and build a brand new style declaration so that the above might end up as:
The only way this works is for the compiler to be smart enough to know which styles to copy and which styles not to copy. The most realistic solution is to disallow the use of :extend within a media query in favor of using classic mixins.
c) match everything inside its own media query plus everything not inside another media query, but it should bring that extend inside itself..
I could miss something right now but it sounds logical. You would not commonly put something shared on mixed styles into particular media query, and as well you would not usually need shared styles from another media query set other than you working with. I am obviously missing something :/
@dmi3y - you kind of touch on a point that I don't [currently] endorse anymore. I agree that extend within a media query should:
Match everything within its own media query - which is a very "normal" thing to expect and should be considered implied moving forward IMO (for the sake of typing).
Match everything outside of media queries, but should copy those styles into itself
Even though I agree, the interesting thing about number 2 is we are no longer "extending" but rather duplicating styles in the fashion of a plain ol' mixin. This is very important IMO because the whole idea of :extend was to minimize duplication. But for the time being, let's assume that this is how extend should work within media queries.
By the same token of grabbing everything "outside" of media queries, should we not grab everything in other currently matching media queries? Best shown by example:
.b{} <-- These get copied
@mediaonly screen and(min-width:30em){.b{} // <-- Why shouldn't this get copied? It applies to anything greater than 30em
}@mediaonly screen and(min-width:48em){.a:extend(.b){}}@mediaonly screen and(max-width:60em){.b{} <-- This hurts my head (notice the MAX-width)}
This one you kind of have to wring your brain through. Think of :extend in general usage as a replacement for referencing mixins (so, copying the entire contents of the mixin within your selector).
So, I guess what I'm saying is that I would kind of expect us to do whatever has the same effect as referencing the mixin. Media queries create isolated sets, so I think extends should get walled off. As in:
.b { }
@media only screen and (min-width: 48em) {
.a:extend( .b ) { }
}
// output
.b {
}
@media only screen and (min-width: 48em) {
.a { // EDITED: contains properties of .b, effectively same as using a class as mixin
}
}
Yes, @DesignByOnyx, it would be a copy, but it's not necessarily the SAME copy because of the different ways you can extend (could contain base properties only).
Illustrated more clearly:
.b {
}
.c {
}
.d {
}
@media only screen and (min-width: 48em) {
.a:extend( .b, .c ) { }
}
@media only screen and (max-width: 60em) {
.a:extend( .c, .d ) { }
}
Hopefully, I've made obvious in the above example that the root classes should not be modified. The "result" of .a is local to that media query.
UPDATE:
If it's copying (not modifying the original block) it doesn't really need to include the original.... so the output of the above would end up being:
c) match everything inside its own media query plus everything not inside another media query, but it should bring that extend inside itself.. and leave it, with peace, where they are.
So, I guess, like @Soviut said, classes within a media query have a local scope; therefore the result of :extend must also. It cannot "escape" and modify classes of a broader or different media scope, because that's not what CSS would do.
@MatthewDL - I totally agree with you and @Soviut with extend not "escaping" the scope of the media query. However, there is this issue of copying from outside the media query.
With the example you provided, I would expect a different result. Let me add a property to show you:
.b{padding:5px}@mediaonly screen and(min-width:48em){.a:extend(.b){}}/*.b { padding: 5px }@media only screen and (min-width: 48em) { .a { padding: 5px }}*/
That's what I meant by copying. I ran into this issue in the real world where I wanted an element to inherit my grid styles ONLY beginning at min-width: 48em. Here is some real world code I tried to use with alpha extend:
I personally would expect the .grid-wrap styles to be copied into the media query, the same as writing the following (which is what I ended up with in my real world code):
Does anybody else think this is the way :extend should work? We would get the benefits of using the modifiers (deep, shallow, etc) so that I would really write it like this today:
It would basically work like a mixin call but with the options.. I was trying to think of usecases though and I'm stumped..
We use extend to introduce a new selector to an existing style block.. when will different media queries require new selectors not used outside the query?
Reading @MatthewDL earlier comments persuaded me towards my option. b - no copying from outside the query
@DesignByOnyx - You said you would expect a different result, yet your result looks exactly the same as what I ended up with. Of course, I edited it after I had originally posted it, so if you received via email, you might have seen my original draft. So, yes, I agree, in a media block :extend should essentially behave the same as importing a class, with the one caveat of joining multiple extend calls within the same media block.
@dmi3y - To your above example, I don't agree. The extend is called within the context of that media query, so it is inherently declaring: "Extend this other class, but ONLY in the context of this media query."
As @DesignByOnyx said, the only way to serve that declaration is to copy the styles within the media query, and leave the outside block alone.
@MatthewDL - you did change your example while I was posting. Apologies and glad we are on the same page there. Also, do you consider my example above to be a poor use case (willing to shoot me over)? Aside from the :extend I think it's a perfectly normal scenario:
.b{padding:5px}@mediaonly screen and(min-width:30em){.b{color: red }}@mediaonly screen and(min-width:48em){.a:extend(.b){}}@mediaonly screen and(max-width:60em){.b{background: green }}
I also think it's reasonable to expect that styles are copied from other "matching" media queries. I'm going on a limb here, but consider this output:
.b{padding:5px}@mediaonly screen and(min-width:30em){.b{color: red }}@mediaonly screen and(min-width:48em){.a{padding:5px;color: red;}}@mediaonly screen and(min-width:48em)and(max-width:60em){.a{background: green }}
Notice the brand new media query which was created. I don't want to take this discussion where it doesn't need to go, but I think the above scenario is easily solved and reasonable to expect, no?
EDIT: ... but forgot to mention the most important part. This requires the LESS parser to be able to understand media queries on a whole different level than it does now.
@DesignByOnyx - Yes, that summary seems correct. What is copied into the media query is dictated by the same :extend keywords. So, if I do a deep extend (called from within a media query), then all of the properties / nested selectors are imported into the media query within the selector I wish to extend. Pretty similar to calling a mixin, except for the collapsing behavior I illustrated if I do this multiple times / with multiple selectors (and, you make a good note, ALSO extending the selectors that already exist within that media block).
@dmi3y - Agree with @agatronic and @DesignByOnyx that your previous examples are overkill and I'm afraid your recent example is still slightly incorrect.
.a { ... }
@media ..case1.. {
.b { ... } // contains properties from external .a and local .b
// not ".a, .b { }" because the properties / reference of .a are already inherited into this media block scope
}
Alright, still something is not just agree inside of me with making extend works in a mixin-ish way, yes I know that's not the same, but. In that paticular case I would rather write more in less code in favor of making it logically clear, I might be wrong. But considering example with two extends for one mixin in the same mediaquery.
However, the scope of #header .b and #header .c need to be limited to the @media declaration where they were defined.
So, in cases of @media queries, at times, the behavior is similar to mixins, but it is not the same. :extend collapses within its scope, and can optionally match partial classes or opt to not extend nested selectors, which mixins cannot do. Mixins just output their properties inline.
Finally I do understand it! And support in that point. Probably just not such satisfied with final syntax inside mediaqueries :/ Though it is far away another question. Just still something popping out in my mind about the mediaquery like variant.
.....
@media ..case1... {
@extend (#header .a all) { // IMO more feels that something needs to be copied to this place than moved out
.b{ ... }
.d{ ... }
}
}
and in some circumstances that could be sugared to just
While your @extend syntax is compatible with my example, I feel like in most cases, it will be done at the declaration level. As in, on a case-by-case basis for individual selector declarations, and I don't think people necessarily want to move it around to include it in an @extend block. Because it's a different approach for declaring extend, I feel like it would be confusing to do both. Similar thoughts with the second example. It looks like you're extending the @media query itself, so to support that plus extending selectors feels confusing.
Please feel free to look at the new test case extend-media.less and extend-media.css and suggest anything I've missed or anything you think disagrees with what is in this issue.
Just revisiting this as I ran into an apparent bug today related to this. extend-media.less and extend-media.css appear to have incorrect output according to this thread. See @DesignByOnyx's summary:
An :extend(.a) which takes place within a media query will:
a) Extend every .a within that same media query
b) Copy over all root-level .a styles which exist outside any media query (similar to a mixin)
The second part of this is currently not occurring as of 1.7.5. Selectors outside of @media are being ignored.
Just revisiting this as I ran into an apparent bug today
No, not a really a bug (As I understand it the "copying" was intentionally postponed by @lukeapage for "better times" and that's why this behaviour is mentioned in the docs :)
@seven-phases-max I tried to re-reread as much of the original related issues. I just couldn't find where this was mentioned, so I couldn't tell if it was accidental or intentional. Was that mentioned in the original commit?
Activity
Soviut commentedon Feb 7, 2013
Well what would CSS proper do? How would it react? The closer we are to that, the better. Since media queries are theoretically at the root level in regular CSS, that might give some guidance.
DesignByOnyx commentedon Feb 8, 2013
EDIT: I have since put a lot more time in thought into the
:extendfeature and do not really stand by this comment any more. I would like to leave it here for the purpose of conversation, but this should not be a guideline or a suggestion.I have just run into scenario number 2, and I would like to voice my opinion about it. Let me provide some example code:
After spending much time thinking about this, I don't know that there is really one single elegant solution. The most elegant solution (in my opinion) is for the compiler to copy styles from other media queries and build a brand new style declaration so that the above might end up as:
The only way this works is for the compiler to be smart enough to know which styles to copy and which styles not to copy. The most realistic solution is to disallow the use of
:extendwithin a media query in favor of using classic mixins.dmi3y commentedon Feb 20, 2013
Definitely I like:
I could miss something right now but it sounds logical. You would not commonly put something shared on mixed styles into particular media query, and as well you would not usually need shared styles from another media query set other than you working with. I am obviously missing something :/
DesignByOnyx commentedon Feb 20, 2013
@dmi3y - you kind of touch on a point that I don't [currently] endorse anymore. I agree that
extendwithin a media query should:Even though I agree, the interesting thing about number 2 is we are no longer "extending" but rather duplicating styles in the fashion of a plain ol' mixin. This is very important IMO because the whole idea of
:extendwas to minimize duplication. But for the time being, let's assume that this is howextendshould work within media queries.By the same token of grabbing everything "outside" of media queries, should we not grab everything in other currently matching media queries? Best shown by example:
matthew-dean commentedon Feb 20, 2013
This one you kind of have to wring your brain through. Think of :extend in general usage as a replacement for referencing mixins (so, copying the entire contents of the mixin within your selector).
So, I guess what I'm saying is that I would kind of expect us to do whatever has the same effect as referencing the mixin. Media queries create isolated sets, so I think extends should get walled off. As in:
Yes, @DesignByOnyx, it would be a copy, but it's not necessarily the SAME copy because of the different ways you can extend (could contain base properties only).
Illustrated more clearly:
Hopefully, I've made obvious in the above example that the root classes should not be modified. The "result" of .a is local to that media query.
UPDATE:
If it's copying (not modifying the original block) it doesn't really need to include the original.... so the output of the above would end up being:
dmi3y commentedon Feb 20, 2013
ops, sorry, overlooked, correct myself
matthew-dean commentedon Feb 20, 2013
So, I guess, like @Soviut said, classes within a media query have a local scope; therefore the result of :extend must also. It cannot "escape" and modify classes of a broader or different media scope, because that's not what CSS would do.
matthew-dean commentedon Feb 20, 2013
So I think @DesignByOnyx, @dmi3y - we're all suggesting the same behavior?
dmi3y commentedon Feb 20, 2013
I like how it tastes, but not yet sure
Results to:
DesignByOnyx commentedon Feb 20, 2013
@MatthewDL - I totally agree with you and @Soviut with
extendnot "escaping" the scope of the media query. However, there is this issue of copying from outside the media query.With the example you provided, I would expect a different result. Let me add a property to show you:
That's what I meant by copying. I ran into this issue in the real world where I wanted an element to inherit my grid styles ONLY beginning at
min-width: 48em. Here is some real world code I tried to use with alphaextend:I personally would expect the .grid-wrap styles to be copied into the media query, the same as writing the following (which is what I ended up with in my real world code):
Does anybody else think this is the way
:extendshould work? We would get the benefits of using the modifiers (deep, shallow, etc) so that I would really write it like this today:dmi3y commentedon Feb 20, 2013
As my prospective, you just answered your question, why not just use mixins? Sorry if I missed it again.
lukeapage commentedon Feb 20, 2013
It would basically work like a mixin call but with the options.. I was trying to think of usecases though and I'm stumped..
We use extend to introduce a new selector to an existing style block.. when will different media queries require new selectors not used outside the query?
Reading @MatthewDL earlier comments persuaded me towards my option. b - no copying from outside the query
matthew-dean commentedon Feb 20, 2013
@DesignByOnyx - You said you would expect a different result, yet your result looks exactly the same as what I ended up with. Of course, I edited it after I had originally posted it, so if you received via email, you might have seen my original draft. So, yes, I agree, in a media block :extend should essentially behave the same as importing a class, with the one caveat of joining multiple extend calls within the same media block.
matthew-dean commentedon Feb 20, 2013
@dmi3y - To your above example, I don't agree. The extend is called within the context of that media query, so it is inherently declaring: "Extend this other class, but ONLY in the context of this media query."
As @DesignByOnyx said, the only way to serve that declaration is to copy the styles within the media query, and leave the outside block alone.
DesignByOnyx commentedon Feb 20, 2013
@MatthewDL - you did change your example while I was posting. Apologies and glad we are on the same page there. Also, do you consider my example above to be a poor use case (willing to shoot me over)? Aside from the
:extendI think it's a perfectly normal scenario:I also think it's reasonable to expect that styles are copied from other "matching" media queries. I'm going on a limb here, but consider this output:
Notice the brand new media query which was created. I don't want to take this discussion where it doesn't need to go, but I think the above scenario is easily solved and reasonable to expect, no?
EDIT: ... but forgot to mention the most important part. This requires the LESS parser to be able to understand media queries on a whole different level than it does now.
23 remaining items
matthew-dean commentedon Feb 22, 2013
@DesignByOnyx - Yes, that summary seems correct. What is copied into the media query is dictated by the same :extend keywords. So, if I do a deep extend (called from within a media query), then all of the properties / nested selectors are imported into the media query within the selector I wish to extend. Pretty similar to calling a mixin, except for the collapsing behavior I illustrated if I do this multiple times / with multiple selectors (and, you make a good note, ALSO extending the selectors that already exist within that media block).
@dmi3y - Agree with @agatronic and @DesignByOnyx that your previous examples are overkill and I'm afraid your recent example is still slightly incorrect.
...creates:
dmi3y commentedon Feb 22, 2013
@MatthewDL thanks, corrected. Yes, now it fits better in my head, especially with your previous clarifications.
dmi3y commentedon Feb 22, 2013
Alright, still something is not just agree inside of me with making extend works in a mixin-ish way, yes I know that's not the same, but. In that paticular case I would rather write more in less code in favor of making it logically clear, I might be wrong. But considering example with two extends for one mixin in the same mediaquery.
and having than
would not be it something similar to this approach?
matthew-dean commentedon Feb 22, 2013
@dmi3y - As stated, similar, but not the same. Extend has more options. For example:
becomes:
The reason is that without a media query, it would output like this:
However, the scope of
#header .band#header .cneed to be limited to the @media declaration where they were defined.So, in cases of @media queries, at times, the behavior is similar to mixins, but it is not the same.
:extendcollapses within its scope, and can optionally match partial classes or opt to not extend nested selectors, which mixins cannot do. Mixins just output their properties inline.dmi3y commentedon Feb 22, 2013
Finally I do understand it! And support in that point. Probably just not such satisfied with final syntax inside mediaqueries :/ Though it is far away another question. Just still something popping out in my mind about the mediaquery like variant.
and in some circumstances that could be sugared to just
Does it make any sense? Or I am too wired today;)
matthew-dean commentedon Feb 22, 2013
While your @extend syntax is compatible with my example, I feel like in most cases, it will be done at the declaration level. As in, on a case-by-case basis for individual selector declarations, and I don't think people necessarily want to move it around to include it in an @extend block. Because it's a different approach for declaring extend, I feel like it would be confusing to do both. Similar thoughts with the second example. It looks like you're extending the @media query itself, so to support that plus extending selectors feels confusing.
dmi3y commentedon Feb 23, 2013
Yes, agree, that's another level of complication, which is not good.
lukeapage commentedon Mar 4, 2013
Please feel free to look at the new test case
extend-media.lessandextend-media.cssand suggest anything I've missed or anything you think disagrees with what is in this issue.matthew-dean commentedon Sep 17, 2014
Just revisiting this as I ran into an apparent bug today related to this. extend-media.less and extend-media.css appear to have incorrect output according to this thread. See @DesignByOnyx's summary:
The second part of this is currently not occurring as of 1.7.5. Selectors outside of @media are being ignored.
seven-phases-max commentedon Sep 17, 2014
No, not a really a bug (As I understand it the "copying" was intentionally postponed by @lukeapage for "better times" and that's why this behaviour is mentioned in the docs :)
matthew-dean commentedon Sep 17, 2014
@seven-phases-max I tried to re-reread as much of the original related issues. I just couldn't find where this was mentioned, so I couldn't tell if it was accidental or intentional. Was that mentioned in the original commit?
One of the reasons I want to keep track is sometimes we implement part of a feature, then close the issue, and don't track the remainder of the feature. If we have a central way to track it, then maintainers may have something easier to point to when someone asks a related question, to the effect of: "Yes, we're planning on that, here's the feature spec, sub-features A,B,C have been implemented, sub-features X,Y,Z have yet to be implemented." Something like what W3C does with CSS3 specs. http://www.w3.org/Style/CSS/current-work
seven-phases-max commentedon Sep 17, 2014
I'm assuming one could not "not to code" a relatively large piece of code by accident and then documenting this in very details :).
matthew-dean commentedon Sep 17, 2014
Maybe I'll start something in the wiki...
matthew-dean commentedon Sep 17, 2014
Ha. I could. ;-)