- Below is how you can target
p
element and max-width
or min-width
:
@media screen and (min-width: 900px) {
p {
background: black;
color: white;
}
}
@media screen and (max-width: 900px) {
p {
background: blue;
color: white;
}
}
- It is preferable to use device-size in LWC. Below is how it behaves:
size
is mandatory when you want custom responsive design by defining large, mediu and small.
size
starts from 0 width.
- When you just give
size
and medium-device-size
, size will be taken for 0 to medium width. Sample is with small or large.
small
is actually the horizontal view for almost all mobiles - this is very important point. Therefore size
should be maximum parts always to accommodate mobile vertical view.
Below are the examples:
- Consider below code:
<lightning-layout multiple-rows>
<lightning-layout-item size="4" small-device-size="12">
... content ...
</lightning-layout-item>
<lightning-layout-item size="4" small-device-size="12">
... content ...
</lightning-layout-item>
<lightning-layout-item size="4" small-device-size="12">
... content ...
</lightning-layout-item>
</lightning-layout>
This will render 3 columns in mobile vertical view and single column in mobile horizontal view. So, you need size
to be maximum parts of all device sizes always - which means 12
in this case.
- For below example:
<lightning-layout-item size="12" large-device-size="4">
... content ...
</lightning-layout-item>
<lightning-layout-item size="12" large-device-size="4">
... content ...
</lightning-layout-item>
<lightning-layout-item size="12" large-device-size="4">
... content ...
</lightning-layout-item>
For big screens, you get 3 columns and for any device less it will be single column
- For below example:
<lightning-layout-item size="12" large-device-size="4" medium-device-size="6" small-device-size="12">
... content ...
</lightning-layout-item>
<lightning-layout-item size="12" large-device-size="4" medium-device-size="6" small-device-size="12">
... content ...
</lightning-layout-item>
This is straight forward - mobile vertical or horizontal view will have single columns. Medium devices like pads will have 2 columns and desktops will have 3 columns.