样式组件不覆盖背景

发布于 2025-01-13 06:25:36 字数 986 浏览 0 评论 0原文

下面,Button 的所有属性都将覆盖 PillButton 的属性除了背景。我尝试过 background-color 得到了相同的结果。只有将 !important 添加到 background 才有效。

const { white, darkGrey } = theme.colors;
export const PillButton = styled.button`
  align-items: center;
  background: ${p => (p.selected ? white : darkGrey)};
  border-radius: 25px;
  border: none;
  color: ${p => (p.selected ? darkGrey : white)};
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding: 8px 16px;
  white-space: nowrap;

  :hover {
    background: ${white};
    color: ${darkGrey};
  }
`;

const Button = styled(PillButton)`
    text-transform: uppercase;
    font-weight: 700;
    font-size: 13px;
    background: ${p =>
      p.selected ? theme.colors.draftedBlue : theme.colors.midGrey};
    font-family: "Roboto Condensed", sans-serif;
  `;

Why isn't background working?

In the following, all the properties of Button are overriding the properties of PillButton except background. I've tried background-color with the same result. Only adding !important to background works.

const { white, darkGrey } = theme.colors;
export const PillButton = styled.button`
  align-items: center;
  background: ${p => (p.selected ? white : darkGrey)};
  border-radius: 25px;
  border: none;
  color: ${p => (p.selected ? darkGrey : white)};
  cursor: pointer;
  display: flex;
  justify-content: center;
  padding: 8px 16px;
  white-space: nowrap;

  :hover {
    background: ${white};
    color: ${darkGrey};
  }
`;

const Button = styled(PillButton)`
    text-transform: uppercase;
    font-weight: 700;
    font-size: 13px;
    background: ${p =>
      p.selected ? theme.colors.draftedBlue : theme.colors.midGrey};
    font-family: "Roboto Condensed", sans-serif;
  `;

Why isn't background working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文