【问题标题】:svg interfering with the buttonsvg 干扰按钮
【发布时间】:2020-06-02 14:17:18
【问题描述】:

我在页面的背景中使用了 svg,但是这个 svg 干扰了按钮的样式。按钮应该全是绿色的,但 svg 线出现在按钮内。 svg 和按钮位于不同的 div 中。 我尝试使用 z-index 将 svg 放在所有组件后面,但没有奏效。

按钮的外观:

按钮的外观:

HTML 代码:

export default function LoginPage() {
  return (
    <Container>
      <PositionLoginImage>
        <Login color="#fff" />
      </PositionLoginImage>
      <Content>
        <CardLogin>
          <PositionLogo>
            <Logo color={theme.colors.marketplace} />
          </PositionLogo>
          <PositionInputUser>
            <p>Usuário</p>
            <Input>
              <span>
                <IconUsers color={theme.colors.marketplace} />
              </span>
              <input type="text" placeholder="Usuário" />
            </Input>
          </PositionInputUser>
          <PositionInputPassword>
            <p>Senha</p>
            <Input>
              <span>
                <IconKey color={theme.colors.marketplace} />
              </span>
              <input type="password" placeholder="Senha" />
            </Input>
          </PositionInputPassword>
          <PositionButton>
            <Link to="/dashboard">
              <Button>Entrar</Button>
            </Link>
          </PositionButton>
        </CardLogin>
      </Content>
    </Container>
  );
}

CSS:

const Container = styled.div`
  min-height: 100vh;
  background-color: ${props => props.theme.colors.marketplace};
  display: flex;
  align-items: center;
  justify-content: center;
`;

const Content = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
`;

const PositionLoginImage = styled.div`
  position: absolute;
  top: 147px;
  left: -0.00048828125px;

  svg {
    width: 100vw;
    height: 40vw;
  }
`;

const PositionLogo = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 40px;
`;

const CardLogin = styled.div`
  width: 581px;
  height: 722px;
  background: #fff;
  box-shadow: 0px 4px 16px #455b630f;
  border-radius: 10px;
`;

const PositionInputUser = styled.div`
  display: grid;
  align-items: center;
  justify-content: center;
  margin-top: 90px;

  p {
    font-size: 20px;
    font-weight: 600;
    color: ${props => props.theme.colors.textTitle};
  }
`;

const PositionInputPassword = styled.div`
  display: grid;
  align-items: center;
  justify-content: center;
  margin-top: 35px;

  p {
    font-size: 20px;
    font-weight: 600;
    color: ${props => props.theme.colors.textTitle};
  }
`;

const PositionButton = styled.div`
  display: grid;
  align-items: center;
  justify-content: center;
  margin-top: 90px;
`;

export const Button = styled.button`
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-top: 4px;
  padding-left: 15px;
  padding-right: 15px;
  width: 206px;
  height: 54px;
  border-radius: 10px;
  border: 1px solid ${props => props.theme.colors.marketplace};
  background-color: ${props => props.theme.colors.marketplace};

  font-size: 18px;
  line-height: 22px;
  color: #fff;
`;

export const Input = styled.div`
  display: grid;
  grid-template-columns: 64px 1fr;
  width: 445px;
  height: 55px;
  border-radius: 10px;

  span {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f8f8;
  }

  input {
    background-color: #f8f8f8;
  }

  input::-webkit-input-placeholder {
    color: ${props => props.theme.colors.primary};
    opacity: 0.3;
  }
`;

【问题讨论】:

  • 您需要检查此按钮并查看您设置的指定值是否处于活动状态 - 您可能还需要记录 props.theme.colors.marketplace 的值

标签: html css reactjs svg


【解决方案1】:

我在 Content div 中添加了一个 position: relative;,它起作用了。

代码:

const Content = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
`;

【讨论】:

    【解决方案2】:

    您需要明确地为PositionButton 提供纯色背景色:

    const PositionButton = styled.div`
      display: grid;
      align-items: center;
      justify-content: center;
      margin-top: 90px;
      background-color: rgb(14, 211, 156);
    `;
    

    【讨论】:

    • 我认为她在Button 中添加了明确的background-color,这是在PositionButton 中,因为最后一个元素hight = 0 by default
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 2021-12-23
    • 2012-01-05
    • 2019-06-08
    相关资源
    最近更新 更多