This code snippet provides a mechanism to control the visibility of content based on the device type (desktop or mobile) using CSS rules and HTML elements.
CSS Rule | Description |
---|---|
[d-dk] .someclass |
Applies styles to .someclass on desktop devices only. |
[d-mb] .someclass |
Applies styles to .someclass on mobile devices only. |
.no-s-dk |
Hides the element on screens wider than or equal to 768px. |
.no-s-mb |
Hides the element on screens narrower than 768px. |
.no-d-dk |
Hides the element on desktop devices. |
.no-d-mb |
Hides the element on mobile devices. |
.no-t-light-flex , .no-t-light |
Hides elements with these classes. |
.no-t-light-flex |
Displays elements with these classes when the theme is dark and has .no-t-light-flex . |
.no-t-light |
Displays elements with these classes when the theme is dark and has .no-t-light . |
.no-t-dark |
Hides elements with these classes when the theme is dark. |
.snippet
: This class sets the display property to none
, hiding the element.[d-dk] .example-desktop
: This selector targets elements with the class example-desktop
within a specific attribute [d-dk]
(not defined in the snippet). It sets their display property to block
, making them visible on desktop devices.[d-mb] .example-mobile
: This selector targets elements with the class example-mobile
within a specific attribute [d-mb]
(not defined in the snippet). It sets their display property to block
, making them visible on mobile devices.[d-dk]
: This attribute selector targets elements within a specific attribute (not defined in the snippet), presumably indicating a desktop device.[d-mb]
: This attribute selector targets elements within a specific attribute (not defined in the snippet), presumably indicating a mobile device. .snippet {
display: none;
}
[d-dk] .example-desktop {
display: block;
}
[d-mb] .example-mobile {
display: block;
/* .... */
}
<div class="example-desktop snippet">
Content for desktop
</div>
<div class="example-desktop snippet">
Another content for desktop
</div>
<div class="example-mobile snippet">
Content for mobile
</div>
or
<div class="no-d-mb">
Content for desktop
</div>
<div class="no-d-dk">
Content for mobile
</div>
<div class="no-t-light-flex">
Content displayed flexibly in dark mode
</div>
<div class="no-t-light">
Content displayed in light mode
</div>
<div class="no-t-dark">
Content hidden in dark mode
</div>
In this example, the following classes are used:
no-t-light-flex
: Displays content flexibly in dark mode.no-t-light
: Displays content in light mode.no-t-dark
: Hides content in dark mode.<div class="no-s-dk">
Content hidden on screens wider than or equal to 768px
</div>
<div class="no-s-mb">
Content hidden on screens narrower than 768px
</div>