Note: don't focus on the purpose of this code, it's only a minimalist example to highlight the issue encoutered.
When I'm using the box-shadow
property, it sometimes doesn't fit the element's sides, resulting by a 1px (or less) margin between the element and its shadow. Here is an example, using transform
to raise the issue (I think this is not the only way to get it):
h1 {
width: 100px;
text-align: center;
margin: 25px 55px;
background: black;
box-shadow: 30px 0 0 black, -30px 0 0 black;
font-size: 24px;
line-height: 50px;
/* I use 0.5px to show the bug, I would use n% in real conditions */
transform: translate(0.5px, 0);
}
h1 a {
color: white;
text-decoration: none;
}
<h1><a href="#">Foo</a></h1>
If you don't see anything, try to look the full-screen snippet, and resize your browser (I got the issue with Chrome and Firefox). Below is a picture with several screenshots I made, and the (obvious) expected result:
Does anybody faced this issue?
Looks like a browser one, but can we find a workaround to avoid these margins?
EDIT
I've found something new: if I set a box-shadow on a single side, the gap doesn't occurs, using Chrome (it's still here with Firefox):
h1 {
width: 100px;
text-align: center;
margin: 25px 55px;
background: black;
box-shadow: 30px 0 0 black, -30px 0 0 black;
font-size: 24px;
line-height: 50px;
/* I use 0.5px to show the bug, I would use n% in real conditions */
transform: translate(0.5px, 20px);
}
h1 a {
color: white;
text-decoration: none;
}
h1:nth-child(2) {
box-shadow: 30px 0 0 black;
}
h1:nth-child(3) {
box-shadow: -30px 0 0 black;
}
<h1><a href="#">Foo</a></h1>
<h1><a href="#">Foo</a></h1>
<h1><a href="#">Foo</a></h1>