Codepen to reproduce
I've been working on this little drop-down list, when I noticed something odd. The font-weight
property is display differently accross browsers and devices. In Firefox for example applying font-weight
doesn't visibly change anything at all, while in Chrome the font-weight
is rendered except for italic
text [as expected Edge behaves exactly like Chrome] and on Android the font-weight
works as it should.
The font-stack I use:
font-family: -apple-system, BlinkMacSystemFont,
"Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans",
"Droid Sans", "Helvetica Neue", sans-serif;
The font-weight
is supposed to appear on hover
:
.select .list .item:hover {
font-weight: 500;
}
My code:
html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
}
body {
display: grid;
place-items: center;
height: 100vh;
margin: 0;
background-color: #fafafa;
}
.select {
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
.select {
position: relative;
display: inline-block;
padding-bottom: 7px;
}
.select:hover .list {
display: inline-flex;
}
.select .list {
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
display: none;
flex-direction: column;
min-width: 180px;
background-color: #fff;
border: solid 1px #eceff1;
border-radius: 4px;
box-shadow: 0 0 8px -2px rgba(0, 0, 0, 0.125);
box-sizing: content-box;
}
.select .list::before {
content: "";
position: absolute;
left: 50%;
height: 12px;
width: 12px;
background-color: #fff;
border-width: 1px 0 0 1px;
border-style: solid;
border-color: #eceff1;
border-top-left-radius: 2px;
transform: translate(-50%, calc(-50% - 1px)) rotate(45deg);
}
.select .list .item {
padding: 0.125rem 1rem;
margin: 0.375rem 0;
cursor: pointer;
}
.select .list .item:hover {
font-weight: 500;
}
.select .list .group:not(:last-child) {
display: inherit;
flex-direction: inherit;
border-bottom: solid 1px #eceff1;
}
<div class="select">
<button>Button</button>
<div class="list">
<div class="group">
<div class="item">Chrome</div>
<div class="item">Safari</div>
<div class="item">Firefox</div>
</div>
<div class="item" style="font-style: italic; font-size: .875rem;">Edit List</div>
</div>
</div>