样式组件内的伪类选择器
我对一些非常简单的事情有点受阻。 我尝试在样式组件中添加伪类选择器。 仅在悬停时向链接元素添加一些背景 但他似乎不认识伪类,因为里面的 css 没有应用 如果有人能帮我弄清楚为什么不这样做,这将挽救生命哈哈
下面的代码
import React from "react";
import styled from "styled-components";
import { Link } from "react-router-dom";
import { config } from "../../configFile";
import { StyledTitle, StyledSpan, StyledBasicLink } from "../../utils/style/Styled";
const Button = styled(Link)`
display: flex;
justify-content: center;
padding: 10px 15px;
color: #f7f7f7;
text-decoration: none;
font-size: 18px;
text-align: center;
align-items: center;
&:hover {
background-color: darken(#000000, 5%);
border-radius: 5px;
}
`
I'm kinda blocked on something pretty simple.
I try to add a pseudo class selector inside a styled-components.
Only to add some background to a link element when hover
But it seems that he doesn't recognize the pseudo class since the css inside isn't applicated
If anyone can help me figure out why it doesn't it would be life saving haha
Code below
import React from "react";
import styled from "styled-components";
import { Link } from "react-router-dom";
import { config } from "../../configFile";
import { StyledTitle, StyledSpan, StyledBasicLink } from "../../utils/style/Styled";
const Button = styled(Link)`
display: flex;
justify-content: center;
padding: 10px 15px;
color: #f7f7f7;
text-decoration: none;
font-size: 18px;
text-align: center;
align-items: center;
&:hover {
background-color: darken(#000000, 5%);
border-radius: 5px;
}
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为做到这一点的一种方法是向您的控件添加一个事件处理程序,以便当发生悬停/鼠标悬停时,它会向您的组件添加一个 css 类以更改背景颜色和边框半径。
I think that one way to do this would be to add an event handler to your control so that when hover/mouseOver happens it would add a css class to your component to change the background-color and border-radius.