Before and After pseudo classes used with styled-components

前端 未结 4 1762
抹茶落季
抹茶落季 2020-12-28 12:23

What is the proper way to apply :before and :after pseudo classes to styled components?

I know that you can use

&:hover

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 13:18

    This will print the triangle at middle of the div.

    const LoginBackground = styled.div`
      & {
        width: 30%;
        height: 75%;
        padding: 0.5em;
        background-color: #f8d05d;
        margin: 0 auto;
        position: relative;
      }
      &:after {
        border-right: solid 20px transparent;
        border-left: solid 20px transparent;
        border-top: solid 20px #f8d05d;
        transform: translateX(-50%);
        position: absolute;
        z-index: -1;
        content: "";
        top: 100%;
        left: 50%;
        height: 0;
        width: 0;
      }
    `;
    

提交回复
热议问题