简体   繁体   English

如何更改文本区域的边框颜色:focus

[英]How to change border color of textarea on :focus

I want to change border color of TEXTAREA on focus.我想在焦点上更改 TEXTAREA 的边框颜色。 But my code doesn't seem to working properly.但我的代码似乎无法正常工作。

The code is on fiddle .代码在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这是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;
 }
.input:focus {
    outline: none !important;
    border:1px solid red;
    box-shadow: 0 0 10px #719ECE;
  }

There is an input:focus as there is a textarea:focus有一个 input:focus 因为有一个 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;
    }

Probably a more appropriate way of changing outline color is using the outline-color CSS rule.可能更合适的更改轮廓颜色的方法是使用outline-color CSS 规则。

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. box-shadow并不是完全一样的东西,它看起来可能与轮廓不同,尤其是当您将自定义样式应用于元素时。

so simple :很简单 :

 outline-color : green!important;

the whole CSS for my react-boostrap button is:我的 react-boostrap 按钮的整个 CSS 是:

 .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;
 }

Try out this probably it will work试试这个可能会起作用

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

On my personal code I removed the border property because it changed component size.在我的个人代码中,我删除了border属性,因为它改变了组件大小。

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

你只需要在 scss 变量中

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

You can use CSS's pseudo-class to do that.您可以使用 CSS 的pseudo-class来做到这一点。 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.有一个::focus伪类用于选择具有焦点的元素。 So you can hook it in your CSS like this所以你可以像这样在你的 CSS 中钩住它

Using class使用类

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

Using Id使用 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; }

This will work fine.这将正常工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM