【问题标题】:Error in placing and scaling elements in a flex在 flex 中放置和缩放元素时出错
【发布时间】:2021-05-25 00:32:42
【问题描述】:

所以我尝试使用 HTML 和 SASS 构建一个小型网站。我正在自定义一个表单输入框,如图form input box 所示,而它的出现与my error 非常相似。

HTML

<form action="input">
    <input id="email" type="email" placeholder="Email Address" autocomplete="off">
    <img id="error" src="/assets/images/icon-error.svg" alt="error.svg">
    <button type="submit">
        <img id="arrow" src="/assets/images/icon-arrow.svg" alt="">
    </button>
</form>

SASS:

form {
    display: flex;
    align-content: center;
}
    
#email {
    outline: none;
    background: none;
    border-color: $desaturatedRed;
    border-style: solid;
    border-width: thin;
    border-radius: 50px;
    width: 70%;
    height: 50px;
    padding-left: 5%;
    
    &::placeholder {
        color: $desaturatedRed;
        font-family: 'Josefin Sans', sans-serif;
    }
}
    
button {
    width: 20%;
    height: 50px;
    outline: none;
    background: $gradient2;
    border-radius: 50px;
    align-content: center;
    border-style: none;
    cursor: pointer;
    margin-left: -8%;
    visibility: hidden;
}
    
#error {
    margin-left: -10%;
    }

SASS 变量.SASS:

$desaturatedRed: hsl(0, 36%, 70%);
$softRed: hsl(0, 93%, 68%);
$darkGrayRed: hsl(0, 6%, 24%);
$gradient1: linear-gradient(135deg, hsl(0, 0%, 100%), hsl(0, 100%, 98%));
$gradient2: linear-gradient(135deg, hsl(0, 80%, 86%), hsl(0, 74%, 74%));

请帮帮我。

【问题讨论】:

  • 请输入所有代码。它错过了去饱和。
  • 我已经在问题中添加了变量。我认为它没有太大的联系。

标签: css sass flexbox


【解决方案1】:

没有看到 svg 代码 ....

您似乎根本没有为带有 svg 的图像元素设置大小。

Flexbox 并不是所有定位任务的助手。在这种情况下,您可以使用绝对定位而不是 flexbox。

也许你想在 SASS 中尝试类似的东西:

form {
  //  --> use absolute positioning
  // display: flex;
  // align-items: center;
  position: relative;

  // --> size wrapper element for correct inner absolute positioning
  width: 70%;
}

#email {
  // inner element full width as wrapper element is sized
  width: 100%;
  // --> avoid unwhanted sizing effects using padding in input
  box-sizing: border-box;

  outline: none;
  background: none;
  border-color: $desaturatedRed;
  border-style: solid;
  border-width: thin;
  border-radius: 50px;
  height: 50px;
  padding-left: 5%;

  &::placeholder {
    color: $desaturatedRed;
    font-family: "Josefin Sans", sans-serif;
  }
}

button {
  // --> absolute positioning right
  position: absolute;
  top: 0;
  right: 0;

  width: 20%;
  height: 50px;
  outline: none;
  background: $gradient2;
  border-radius: 50px;
  align-content: center;
  border-style: none;
  cursor: pointer;

  // margin-left: -8%; --> not needed as of absolute positioning
  // visibility: hidden; --> not seen when hidden ?!
}

#error {
  // --> absolute positioning from right with vertical centering
  position: absolute;
  right: 22%;
  top: 0;
  bottom: 0;
  margin: auto 0;

  // --> sizing svg-image
  height: 35px;   // or similar
  width: 35px;    // or similar
}

#arrow {
  // --> sizing svg-image
  height: 50px;
  width: auto;   // depends on svg
}


【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 2016-07-24
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多