How can I position a CSS :before
element in front of the foreground content?
I am trying to move the text behind the gray area where the dropdown arrow is located.
I have already attempted to set the z-index of the before element to 2 and the actual element to 1 but it did not seem to have any impact so far. The text keeps overlapping the select arrow of the dropdown menu, which doesn't look good to me.
My current idea is to place the before element on top of the select/option element of the dropdown menu so that the text goes behind the gray area. However, it appears that the z-index is being ignored for these pseudo-elements for some reason...
Can anyone provide some insight on this issue?
https://i.sstatic.net/THq8h.png
HTML:
<div role="button" type="button" data-toggle="dropdown" class="btn dropdown category-dropdown">
<span>{{ category_objects.category }}</span>
</div>
Raw browser output:
<div role="button" type="button" data-toggle="dropdown" class="btn dropdown category-dropdown">
<span><select name="category" id="id_category">
<option value="d6f13bec-f855-453b-ad2f-a426a42bde06">Hello World 1232i</option>
</select></span>
</div>
CSS:
.category-dropdown {
z-index: 1;
}
.category-dropdown select {
background-color: #FFFFFF;
height: 31.5px;
color: #424242;
border: 0;
margin: 0;
width: 10vw;
max-width: 200px;
min-width: 125px;
border-radius: 3px;
text-indent: 3px;
-moz-appearance: none;
-webkit-appearance: none;
}
.category-dropdown::before,
.category-dropdown::after {
content: "";
position: absolute;
pointer-events: none;
}
.category-dropdown::after { /* Custom dropdown arrow */
content: "\25BC";
font-size: .625em;
line-height: 1;
right: 20px;
top: 20px;
margin-top: -.5em;
}
.category-dropdown select {
-webkit-appearance: none;
-moz-appearance: none;
text-overflow: '';
}
.category-dropdown::before {
width: 1.5em;
right: 9px;
top: 6px;
bottom: 5px;
border-radius: 0 3px 3px 0;
margin-right: 3px;
position: absolute;
z-index: 2;
}
.category-dropdown select[disabled] {
color: rgba(0, 0, 0, .3);
}
.category-dropdown select[disabled]::after {
color: rgba(0, 0, 0, .1);
}
.category-dropdown::before {
background-color: rgba(0, 0, 0, .15);
}
.category-dropdown::after {
color: rgba(0, 0, 0, .4);
}
All other CSS-related styles are inherited from bootstrap.