Z-index utilities Since v1.1.0+
Halfmoon comes with responsive utility classes which can be used to set the z-index property of elements. This determines the ordering of elements along the z-axis.
Commenting
|
New message!
Jane Doe just sent you a new message.
|
Halfmoon comes with responsive utility classes which can be used to set the z-index property of elements. This determines the ordering of elements along the z-axis.
The class names for the z-index utilities come in the the following formats:
The {breakpoint} can be sm, md, lg, or xl. If the breakpoint is not provided, the element will be affected on all screen sizes (including extra small screens). On the other hand, if it is provided, the element will be affected only for that breakpoint and up.
The {value} can be one of the following:
{value} | Description |
---|---|
0 | Sets the z-index: 0 property |
10 | Sets the z-index: 10 property |
20 | Sets the z-index: 20 property |
30 | Sets the z-index: 30 property |
40 | Sets the z-index: 40 property |
50 | Sets the z-index: 50 property |
auto | Sets the z-index: auto property |
You can see some of these classes in action in the example below:
<!-- First container -->
<div class="position-relative"> <!-- position-relative = position: relative -->
<div class="position-absolute">Box 1.1</div> <!-- position-absolute = position: absolute -->
<div class="position-absolute m-20">Box 1.2</div> <!-- position-absolute = position: absolute, m-20 = margin: 2rem (20px) -->
</div>
<!-- Second container (with z-index set) -->
<div class="position-relative"> <!-- position-relative = position: relative -->
<div class="z-30 position-absolute">Box 2.1</div> <!-- z-30 = z-index: 30, position-absolute = position: absolute -->
<div class="z-10 position-absolute m-20">Box 2.2</div> <!-- z-10 = z-index: 10, position-absolute = position: absolute, m-20 = margin: 2rem (20px) -->
</div>
<!-- Third container (with z-index set only for medium screens and up) -->
<div class="position-relative"> <!-- position-relative = position: relative -->
<div class="z-md-50 position-absolute">Box 3.1</div> <!-- z-md-50 = z-index: 50 only on medium screens and up (> 768px), position-absolute = position: absolute -->
<div class="z-md-0 position-absolute m-20">Box 3.2</div> <!-- z-md-0 = z-index: 0 only on medium screens and up (> 768px), position-absolute = position: absolute, m-20 = margin: 2rem (20px) -->
</div>
In the above example, the boxes in the first container do not have the z-index set. This means that Box 1.2 is on top of Box 1.1 because it comes after it in the DOM. In the second container, the z-index is set explicitly to make sure that Box 2.1 comes on top of Box 2.2, even though it comes before it in the DOM.
In the third set of boxes, the natural ordering of the boxes along the z-axis is altered only on medium screens and up (width > 768px). Below this width, the ordering will go back to default, with Box 3.2 coming on top, as it comes last in the DOM. You can try resizing your browser window (if you can) to see this for yourself.
Moreover, the width, height, background color, and border of the boxes are set using utility classes. This is not shown in the code for the sake of conciseness.
Our goal is to make Halfmoon the go-to framework for building dashboards and tools on the web. We are already working on things like a form validator, number input, datepicker, multi-select (think Select2 without jQuery), tabs component, JSX docs, and so much more. You can learn more in the project roadmap.
However, we need your help to grow. So if you truly believe in our goal, please consider supporting us through Patreon.
The following is the highest tier, with a maximum of 1 sponsor.
(Also seen at the top of the page)
The following is the normal tier, with a maximum of 10 sponsors.
AYCD
Automation Done Right
Sponsor (9 available)
Halfmoon needs your support! Become a sponsor to place an image and description of your product here. Click here
The following people have generously decided to support Halfmoon.
Become a backer on Patreon .