admin管理员组文章数量:1405349
Pseudo elements are widely used for design. In the example below you'll see a pseudo element (::before
) that's used to give a secondary background to a button, the use case is for adding some hover animation but the animation is not implemented here since that's not the issue.
The issue is that even tho the pseudo element is set to height and width of 100% you can still see a tiny bit of the parent element:
What you see in this image are two buttons. Both of them have a ::before
element with background-color set to green, and height and width of 100%. The difference is that the button on the left has background-color set to white, and the right one set to the same green of the ::before
element. If you'll look closely enough you can see how in the left button you can see the white background of the button.
Code example:
* {
box-sizing: border-box;
}
body {
background: black;
}
button {
position: relative;
padding: 10px;
margin: 0;
border: none;
background-color: white;
z-index: 0;
overflow: hidden;
border-radius: 50px;
border: 0;
}
button::before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: green;
z-index: -1;
}
button:nth-child(2) {
background-color: green;
}
<div>
<button>button</button>
<button>button</button>
</div>
本文标签:
版权声明:本文标题:html - Why an absolute pseudo element with full height and width still shows a little bit of relative parent when border radius 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744893642a2630932.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论