Basic¶
Description: The medias Object groups media instances together in which each child Object is treated as a separate media instance. If a query Object or property is not defined in the media instance, its Object key is used to create a mixin Object.
ctr('.test', {
width: 200px
medias: {
'-sm': {
width: 300px
}
md: {
width: 400px
}
custom: {
query: {
above: 'md'
density: 2
}
width: 500px
}
}
})
.test:
width: 200px
medias:
-sm:
width: 300px
md:
width: 400px
custom:
width: 500px
query:
above: md
density: 2
.test {
width: 200px;
}
@media (max-width: 600px) {
.test {
width: 300px;
}
}
@media (min-width: 600px) and (max-width: 800px) {
.test {
width: 400px;
}
}
@media (min-width: 800px) and (min-resolution: 2dppx) {
.test {
width: 500px;
}
}
ctr('.test', {
width: 200px
medias: {
'-sm': {
width: 300px
}
md: {
width: 400px
}
custom: {
query: {
above: 'md'
density: 2
}
width: 500px
}
}
})
.test {
width: 200px;
}
@media (max-width: 600px) {
.test {
width: 300px;
}
}
@media (min-width: 600px) and (max-width: 800px) {
.test {
width: 400px;
}
}
@media (min-width: 800px) and (min-resolution: 2dppx) {
.test {
width: 500px;
}
}
.test:
width: 200px
medias:
-sm:
width: 300px
md:
width: 400px
custom:
width: 500px
query:
above: md
density: 2
Notes
- In the
mediasObject, you cannot use anyctrreserved keys that are notmediarelated, such ashover,animation, etc.
Common Key¶
Description: A common Object can be defined in the medias Object to specify common values used by all media instances.
ctr('.test', {
width: 200px
medias: {
// merged into each media
common: {
query: {
type: 'screen'
}
font-size: 1em
}
'-sm': {
width: 300px
}
md: {
width: 400px
}
custom: {
query: {
above: 'md'
density: 2
}
width: 500px
}
}
})
.test:
width: 200px
medias:
-sm:
width: 300px
md:
width: 400px
custom:
width: 500px
query:
above: md
density: 2
# added to all
common:
font-size: 1em
query:
type: screen
.test {
width: 200px;
}
@media only screen and (max-width: 600px) {
.test {
width: 300px;
font-size: 1em;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) {
.test {
width: 400px;
font-size: 1em;
}
}
@media only screen and (min-width: 800px) and (min-resolution: 2dppx) {
.test {
width: 500px;
font-size: 1em;
}
}
ctr('.test', {
width: 200px
medias: {
// merged into each media
common: {
query: {
type: 'screen'
}
font-size: 1em
}
'-sm': {
width: 300px
}
md: {
width: 400px
}
custom: {
query: {
above: 'md'
density: 2
}
width: 500px
}
}
})
.test {
width: 200px;
}
@media only screen and (max-width: 600px) {
.test {
width: 300px;
font-size: 1em;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) {
.test {
width: 400px;
font-size: 1em;
}
}
@media only screen and (min-width: 800px) and (min-resolution: 2dppx) {
.test {
width: 500px;
font-size: 1em;
}
}
.test:
width: 200px
medias:
-sm:
width: 300px
md:
width: 400px
custom:
width: 500px
query:
above: md
density: 2
# added to all
common:
font-size: 1em
query:
type: screen
Notes
commonalias:global- The
commonObject is deep merged into eachmediainstance
Omit¶
Description: A List value for the omit option property in an Object media instance omits specific common values from being merged into the instance. The omit value is defined by the property path relative to the common Object.
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
option: {
// omits type
omit: 'query.type'
}
width: 400px
}
}
})
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
option:
# omits type
omit: query.type
width: 400px
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
option: {
// omits type
omit: 'query.type'
}
width: 400px
}
}
})
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
option:
# omits type
omit: query.type
width: 400px
Notes
- Only
omitvalues are excluded - Conversely, the
pickoptionproperty is the inverse, in that onlypickvalues are merged - Lookup is performed through the lodash
_.getFunction via dot notation:<path>.<to>.<omit>.<property>
Pick¶
Description: A List value for the pick option property in an Object media instance picks specific common values to be merged into the instance. The pick value is defined by the property path relative to the common Object.
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
option: {
// picks type height + max-height
pick: 'height' 'query.max-height'
}
width: 400px
}
}
})
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
option:
# picks type height + max-height
pick: [height, query.max-height]
width: 400px
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
option: {
// picks type height + max-height
pick: 'height' 'query.max-height'
}
width: 400px
}
}
})
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
option:
# picks type height + max-height
pick: [height, query.max-height]
width: 400px
Notes
- Only
pickvalues are merged and all other values are excluded - Conversely, the
omitoptionproperty is the inverse, in that onlyomitvalues are exculed from the merge - Lookup is performed through the lodash
_.getFunction via dot notation:<path>.<to>.<pick>.<property>
Target¶
Description: A List value for the target option property in the common Object specifies specific media instances to merge with.
ctr('.test', {
width: 200px
medias: {
common: {
option: {
// only merges with "md"
target: 'md'
}
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
width: 400px
}
}
})
.test:
width: 200px
medias:
common:
option:
# only merges with "md"
target: md
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
width: 400px
.test {
width: 200px;
}
@media (min-width: 400px) and (max-width: 600px) {
.test {
width: 300px;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
ctr('.test', {
width: 200px
medias: {
common: {
option: {
// only merges with "md"
target: 'md'
}
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
md: {
width: 400px
}
}
})
.test {
width: 200px;
}
@media (min-width: 400px) and (max-width: 600px) {
.test {
width: 300px;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
width: 400px;
height: 222px;
}
}
.test:
width: 200px
medias:
common:
option:
# only merges with "md"
target: md
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
md:
width: 400px
Notes
- An instance is defined by its Object key
- The intended purpose is to aid in debugging
- If an
mediainstance is not defined in the List, it’s not merged with thecommonObject
True Value¶
Description: A true Boolean value for an Object media instance inherits the common Object value.
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
// inherits common
md: true
}
})
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
# inherits common
md: true
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
height: 222px;
}
}
ctr('.test', {
width: 200px
medias: {
common: {
query: {
type: 'screen'
'max-height': 400px
}
height: 222px
}
sm: {
width: 300px
}
// inherits common
md: true
}
})
.test {
width: 200px;
}
@media only screen and (min-width: 400px) and (max-width: 600px) and (max-height: 400px) {
.test {
width: 300px;
height: 222px;
}
}
@media only screen and (min-width: 600px) and (max-width: 800px) and (max-height: 400px) {
.test {
height: 222px;
}
}
.test:
width: 200px
medias:
common:
query:
type: screen
max-height: 400px
height: 222px
sm:
width: 300px
# inherits common
md: true