Search code examples
htmlcssstyling

HTML && CSS Input Border Movement


I have a problem. I am making a register form in HTML and CSS. I putted a border on focus of the input (once you click, border around input appears), but then another inputs start moving around. How can I fix that movements? Here's my code:

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>

I would really appreciate help.


Solution

  • If you want to have increasing border widths, then you could use an inset box shadow instead.

    Also it's good practice to add * { box-sizing: border-box } to avoid issues like this.

    * {
      box-sizing: border-box;
    }
    
    input {
      width: 450px;
      height: 3.5vh;
      margin-bottom: 1rem;
      outline: none;
      color: white;
      border: none;
      box-shadow: inset 0 0 0 1px rgba(170, 170, 170, 0.3);
      background: rgba(0, 0, 0, 0.5);
      font-family: 'Poppins', sans-serif;
      font-weight: bold;
      border-radius: 3px;
      min-height: 40px;
      padding-left: 10px;
    }
    
    input:focus {
      box-shadow: inset 0 0 0 2px 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>