首页 > 解决方案 > HTML && CSS 输入边框移动

问题描述

我有个问题。我正在用 HTML 和 CSS 制作注册表单。我在输入的焦点上放置了一个边框(单击后,会出现输入边框),但随后另一个输入开始移动。我该如何解决这些动作?这是我的代码:

input {
  width: 450px;
  height: 3.5vh;
  margin-bottom: 1rem;
  outline: none;
  color: white;
  border: 1px solid rgba(170, 170, 170, 0.3);
  background: rgba(0, 0, 0, 0.5);
  font-family: 'Poppins', sans-serif;
  font-weight: bold;
  border-radius: 3px;
}

input:focus {
  border: 2px solid blueviolet;
  outline: none!important;
}
<div class="inputs">
  <input type="text" placeholder="User Name" name="name">
</div>
<div class="inputs">
  <input type="email" placeholder="Email" name="email">
</div>
<div class="inputs">
  <input type="password" placeholder="Password" name="password">
</div>
<div class="inputs">
  <input type="password" placeholder="Confirm Password" name="confirmit">
</div>
<span class="img-text">Choose avatar: </span>
<input type="file" id="img" accept="image/*" style="border: none!important; background: none!important;">
<button class="register" type="submit" name="register">Register</button>

我真的很感激帮助。

标签: htmlcssstyling

解决方案


发生这种情况是因为您在焦点上添加了边框,但最初输入标签中没有边框,这就是您面临 UI 波动的原因。

要修复在输入中添加边框属性以及透明度。

input {
    width: 450px;
    height: 3.5vh;
    margin-bottom: 1rem;
    outline: none;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    font-family: 'Poppins', sans-serif;
    font-weight: bold;
    border-radius: 3px;
    border: solid 2px transparent;
}

推荐阅读