简体   繁体   English

将鼠标悬停在没有包装的样式化组件上

[英]Hover on a styled component without wrapper

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. 我只想在Link元素上悬停效果,以将颜色更改为白色。 Any other docs I have seen would have me put a hover call when I call Link: 我看到的任何其他文档都会在我调用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? 如何在链接组件的样式中放置a:hover?

@psion have you checked something like the following code: @psion是否检查了类似以下代码的内容:

const Link = styled.a`
  color: blue;

  &:hover {
    color: white;
  }
`;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 情感/风格 - Hover 在 SVG 组件上 - emotion/styled - Hover on an SVG component 使用样式组件在父级的 hover state 上隐藏子组件 - Hiding child component on hover state of parent using styled-component 使用样式组件添加悬停在冷藏元素上的效果 - Adds the effect of the hover on the chilled element using the styled component :focus 不适用于:hover 与 React.js 的 styled-component - :focus is not working with :hover with styled-component for React.js hover 下划线 - 反应路由器链接与样式组件链接 - hover underline - react router link vs styled-component link 将样式化组件添加到通常的类包装器之外并通过 ajax 调用的引导模式 - Adding styled component to bootstrap modal which is outside of usual class wrapper and called via ajax 尝试根据屏幕宽度有条件地在包装器内部或外部呈现样式化组件时的最佳实践 - Best Practice when trying to conditionally render a styled component inside or outside of wrapper based on screen width 如何使用 props 使用 scss 设置组件样式(不使用样式化组件) - How to style a component with scss using props (without using styled components) 样式化组件不包装另一个样式化组件 - Styled component not wrapping another styled component 如何通过带有样式组件的道具传递 styles 而无需在组件内创建组件 - How to pass styles via props with styled components without having to create the component inside the component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM