Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change border width when focused

I want to change border width when focused. My input box has 1px solid border. When focused, It changes 2px different color solid border. But there is 1px difference, so the div contains this input box changes its width 1px when focus. I want to solve this problem. I am a beginner in html and css so I am looking for your help. Thank you.

.contact-input {
  border: 1px solid #707070;
  border-radius: 10px;
  margin-top: 1.5rem;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.16);
  padding: 1.5rem;
}

.contact-label {
  padding-bottom: 2rem;
}

.contact-input input[type="text"] {
  outline: none;
  border: none;
  border-bottom: 1px solid #707070;
  width: 40%;
}

.contact-input input[type="text"]:focus {
  outline: none;
  border-bottom: 2px solid #3AD6B1;
}
<div class="contact-input">
  <div class="contact-label">Name</div>
  <input class="w-50" type="text" placeholder="Your answer">
</div>
like image 706
Kimura Shinji Avatar asked Mar 20 '26 13:03

Kimura Shinji


1 Answers

add 1px of box-shadow

.contact-input {
    border: 1px solid #707070;
    border-radius: 10px;
    margin-top: 1.5rem;
    box-shadow: 0 3px 3px rgba(0, 0, 0, 0.16);
    padding: 1.5rem;
}
.contact-label {
    padding-bottom: 2rem;
}
.contact-input input[type="text"] {
    outline: none;
    border: none;
    border-bottom: 1px solid #707070;
    width: 40%;
}
.contact-input input[type="text"]:focus {
    outline: none;
    box-shadow:0 1px 0 #3AD6B1;
    border-color:#3AD6B1;
}
<div class="contact-input">
    <div class="contact-label">Name</div>
    <input class="w-50" type="text" placeholder="Your answer">
</div>
like image 88
Temani Afif Avatar answered Mar 23 '26 02:03

Temani Afif



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!