样式化的组件/焦点

时间:2020-02-07 18:42:03

标签: css styled-components

你好,我想当一个组件(h3或div bg img) 悬停还是专注 增加h3的亮度并将框阴影应用于bg img

我无法想象如何使用样式化组件来做到这一点 我的代码:

 <Styled.CardTop background={TestBG3}>
    <div className="Bg" />
    <div className="headerH3">
    <h3>aaaaaaaaa.</h3>
    </div>
  </Styled.CardTop>

具有样式伴奏的CSS:

const CardTop = styled.div`
  position: relative;
  height: 300px;
  width: 100%;
  margin-bottom:40px;
  & .Bg {
    display:flex;
    align-items:center;
    position:relative;
    background-image: url(${({ background }) => background});
    background-size: cover;
    background-repeat: no-repeat;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    height: 200px;
    -o-background-size: cover;
    background-size: cover;
    background-position: center;
    cursor:pointer;
    :hover{
      box-shadow: inset 0 0 100px 100px rgba(0, 0, 0, 0.1);
    }
}
  & .headerH3 {
    padding: 0 10px;
    display:flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
    color:#1976d2;
  :hover,:active{
    filter: brightness(115%);
  }
  }

1 个答案:

答案 0 :(得分:0)

您应该使用&:hover和&:active。 我的示例与您的示例稍有不同,但是您可以看到悬停功能正常

https://codesandbox.io/s/style-with-styled-components-30zww