0
import { FaRegHeart } from 'react-icons/fa';


const IconHeart = styled(FaRegHeart)`

width:21px;
height:18px;
position: absolute;
left: 28%;
top:30%;
cursor: pointer;
&:hover{
 background-color:red;
}
`


function Heart() {
  return (
    <HeartBox>

      <IconHeart />

    </HeartBox>

  )
}

嘉宾:

我完全控制了 svg 图标,悬停在此图标上不起作用。喜欢在图标周围有边框,但是如果我设置边框,他会在图标周围放置边框,而不是在其自身上

4

1 回答 1

3

您需要使用 SVG 的填充属性

const IconHeart = styled(FaRegHeart)`
  width:21px;
  height:18px;
  position: absolute;
  left: 28%;
  top:30%;
  cursor: pointer;

  :hover{
    fill:red;
    }
`

Codesandbox 示例:
https ://codesandbox.io/s/styled-hover-fill-svg-iks37

于 2021-04-08T10:54:19.553 回答