最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hover on a styled component without wrapper - Stack Overflow

programmeradmin1浏览0评论

So I have this:

const Link = styled.a`
    color: blue;
`;

<Wrapper>
    <Link href="/">Hover Change</Link>
<Wrapper>

I want to put a hover effect on just the Link element to change the color to white. Any other docs I have seen would have me put a hover call when I call Link:

const Wrapper=styled.div`
    &:hover ${Link}: white;
';
<Wrapper>
    <Link href="/">Hover Me</Link>
<Wrapper>

How do I place the a:hover in the styling for the Link component?

So I have this:

const Link = styled.a`
    color: blue;
`;

<Wrapper>
    <Link href="/">Hover Change</Link>
<Wrapper>

I want to put a hover effect on just the Link element to change the color to white. Any other docs I have seen would have me put a hover call when I call Link:

const Wrapper=styled.div`
    &:hover ${Link}: white;
';
<Wrapper>
    <Link href="/">Hover Me</Link>
<Wrapper>

How do I place the a:hover in the styling for the Link component?

Share Improve this question asked Jan 24, 2018 at 23:29 psionpsion 7582 gold badges6 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 18

@psion have you checked something like the following code:

const Link = styled.a`
  color: blue;

  &:hover {
    color: white;
  }
`;

<Link href="/">Hover Change</Link>
发布评论

评论列表(0)

  1. 暂无评论