svg干扰按钮

时间:2020-02-18 14:17:37

标签: html css reactjs svg

我在页面背景中使用了一个svg,但是该svg干扰了按钮的样式。该按钮应全部为绿色,但svg线仍显示在该按钮内。 svg和按钮位于单独的div中。 我已经尝试过使用z-index将svg扔到所有组件后面,但是没有用。

按钮的外观:

enter image description here

按钮的外观:

enter image description here

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;
  }
`;

2 个答案:

答案 0 :(得分:1)

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

代码:

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

答案 1 :(得分:0)

您需要为PositionButton赋予纯色,明确地:

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