css3 “::after” pseudo-element not working

2020-04-18 03:31发布

I want to add a triangle after a div tag.Therefore i used css3 after pseudo-element. But it's not working. Following is my css rule.

.header-wrapper .part1 ::after {
    width: 0;
    height: 0;
    border-left: solid 48.35px #f21e1e;
    border-bottom: solid 48.35px transparent;
    border-top: solid 48.35px transparent;
}

Following is my html part

<div class="header-wrapper">
    <div class="part1"></div>
</div>

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-04-18 04:00

In order for the pseudo element to be generated, you need to specify a content value. The value is otherwise assumed to be the default, none - which is likely why it isn't working in your case. (example)

.header-wrapper .part1::after {
    content: '';
    width: 0;
    height: 0;
    border-left: solid 48.35px #f21e1e;
    border-bottom: solid 48.35px transparent;
    border-top: solid 48.35px transparent;
}

Based on the CSS you posted, you should also remove the space between .part1 ::after.

查看更多
登录 后发表回答