How to change border color of textarea on :focus

HtmlCss

Html Problem Overview


I want to change border color of TEXTAREA on focus. But my code doesn't seem to working properly.

The code is on fiddle.

<form name = "myform" method = "post" action="insert.php"  onsubmit="return validateform()" style="width:40%">
    <input type="text" placeholder="Enter Name." name="name" maxlength="300" class="input">
    <input type="email" placeholder="Enter E-mail." name="address" maxlength="300" class="input">
    <textarea placeholder="Enter Message." name="descrip" class="input" ></textarea>	
    <br>
    <input class="button secondary" type=submit name="submit" value="Submit" >
</form>

Here is the CSS

.input {
    border:0; 
    padding:10px; 
    font-size:1.3em; 
    font-family:"Ubuntu Light","Ubuntu","Ubuntu Mono","Segoe Print","Segoe UI";
    color:#ccc; 
    border:solid 1px #ccc; 
    margin:0 0 20px; 
    width:300px;
    -moz-box-shadow: inset 0 0 4px rgba(0,0,0,0.2); 
    -webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2); 
    box-shadow: inner 0 0 4px rgba(0, 0, 0, 0.2);
    -webkit-border-radius: 3px; 
    -moz-border-radius: 3px; 
    border-radius: 3px;    
  }

input:focus { 
    outline: none !important;
    border-color: #719ECE;
    box-shadow: 0 0 10px #719ECE;
 }

Html Solutions


Solution 1 - Html

.input:focus {
    outline: none !important;
    border:1px solid red;
    box-shadow: 0 0 10px #719ECE;
  }

Solution 2 - Html

There is an input:focus as there is a textarea:focus

    input:focus { 
        outline: none !important;
        border-color: #719ECE;
        box-shadow: 0 0 10px #719ECE;
    }
    textarea:focus { 
        outline: none !important;
        border-color: #719ECE;
        box-shadow: 0 0 10px #719ECE;
    }

Solution 3 - Html

Probably a more appropriate way of changing outline color is using the outline-color CSS rule.

textarea {
  outline-color: #719ECE;
}

or for input

input {
  outline-color: #719ECE;
}

box-shadow isn't quite the same thing and it may look different than the outline, especially if you apply custom styling to your element.

Solution 4 - Html

so simple :

 outline-color : green!important;

the whole CSS for my react-boostrap button is:

 .custom-btn {
     font-size:1.9em;
     background: #2f5bff;
     border: 2px solid #78e4ff;
     border-radius: 3px;
     padding: 50px 70px;
     outline-color : blue !important;
     text-transform: uppercase;
     user-select: auto;
     -moz-box-shadow: inset 0 0 4px rgba(0,0,0,0.2);
     -webkit-box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2);
     -webkit-border-radius: 3px;
     -moz-border-radius: 3px;
 }

Solution 5 - Html

This will work fine.

input:focus{
    outline: none;
    border:1px solid red;
}

Solution 6 - Html

Try out this probably it will work

input{
outline-color: #fff //your color
outline-style: none // it depend on you 
}

Solution 7 - Html

you need just in scss varible

$input-btn-focus-width:       .05rem !default;

Solution 8 - Html

You can use CSS's pseudo-class to do that. A pseudo-class is used to define a special state of an element.

there is a ::focus pseudo-class that is used to select the element that has focus. So you can hook it in your CSS like this

Using class

.my-input::focus {
  outline-color: green;
}

Using Id

#my-input::focus {
  outline-color: red;
}

Directly selecting element

input::focus {
  outline-color: blue;
}

Using attribute selector

input[type="text"]::focus {
  outline-color: orange;
}

Solution 9 - Html

On my personal code I removed the border property because it changed component size.

.input:focus {
  outline: none;
  box-shadow: 0 0 0 0.125rem red;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMercurialView Question on Stackoverflow
Solution 1 - HtmlAdriftView Answer on Stackoverflow
Solution 2 - HtmlPhilip SumesgutnerView Answer on Stackoverflow
Solution 3 - HtmlGrgurView Answer on Stackoverflow
Solution 4 - HtmlFarbod AprinView Answer on Stackoverflow
Solution 5 - HtmlTawhid MonowarView Answer on Stackoverflow
Solution 6 - Htmlvicky rajView Answer on Stackoverflow
Solution 7 - HtmlVahid AlvandiView Answer on Stackoverflow
Solution 8 - HtmlHadi MirView Answer on Stackoverflow
Solution 9 - HtmlItalo BrennerView Answer on Stackoverflow