Skip to main content

+responsive

Mixin responsive works similar to mixin +context. The main difference is in semantics and that you can use media queries.

@media queries

+component('button')
+register
+responsive('@media (max-width: 360px)')

+default
display: inline-block
background-color: grey

+responsive('@media (max-width: 360px)')
display: block




button {
display: inline-block;
background-color: grey;
}
@media (max-width: 360px) {
button {
display: block;
}
}

The mixins and functions used in the code above: component, register, default, responsive, mode.


@media queries with alias

+component('button')
+register
+responsive('{<sm}', '@media (max-width: 360px)')

+default
display: inline-block
background-color: grey

+responsive('{<sm}')
display: block




button {
display: inline-block;
background-color: grey;
}
@media (max-width: 360px) {
button {
display: block;
}
}

The mixins and functions used in the code above: component, register, default, responsive.


@media queries with alias defined globally

If you define +global-responsive('{<sm}', '@media (max-width: 360px)') then you can register just alias in every component. See +global-responsive mixin.

+component('button')
+register
+responsive('{<sm}')

+default
display: inline-block
background-color: grey

+responsive('{<sm}')
display: block




button {
display: inline-block;
background-color: grey;
}
@media (max-width: 360px) {
button {
display: block;
}
}

The mixins and functions used in the code above: component, register, default, responsive, global-responsive.


@container queries

The same goes for container queries:

+component('button')
+register
+responsive('@container (max-width: 240px)')
+responsive('@container modal-window (max-width: 360px)')
+responsive('{modal<md}', '@container modal-window (max-width: 720px)')
+responsive('{modal<lg}') // registered globally

+default
display: inline-block
background-color: grey

+responsive('@container (max-width: 240px)')
display: block

+responsive('@container modal-window (max-width: 360px)')
display: inline-flex

+responsive('{modal<md}')
display: flex

+responsive('{modal<lg}')
display: grid



button {
display: inline-block;
background-color: grey;
}
@container (max-width: 240px) {
button {
display: block;
}
}
@container modal-window (max-width: 360px) {
button {
display: inline-flex;
}
}
@container modal-window (max-width: 720px) {
button {
display: flex;
}
}
@container modal-window (max-width: 1024px) {
button {
display: grid;
}
}

The mixins and functions used in the code above: component, register, default, responsive, global-responsive, mode.


It doesn't have to be just @media or @container query

When mutation match the "responsive" semantic then it can be used just like +context mixin with any selector.

+component('button')
+register
+responsive('html.mobile-portrait')

+default
display: inline-block
background-color: grey

+responsive('html.mobile-portrait')
display: block




button {
display: inline-block;
background-color: grey;
}
html.mobile-portrait button {
display: block;
}

The mixins and functions used in the code above: component, register, default, responsive.