Html 用边框和颜色在 div 周围发光
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9752694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
glow around div with border and color
提问by DemCodeLines
Is there any way to add a glow around the div? Look at twitter login and how there is a blue glow around the input box, can that be done for the div?
有没有办法在div周围添加发光?看看 twitter 登录,输入框周围怎么会有蓝色的光芒,这可以为 div 做吗?
采纳答案by m59
Here is the complete code to style a div exactly like the twitter login input. The styles for the blue border are the box-shadow
and border
styles for the selector div[contenteditable]:focus
. Live demo here (click).
下面是完整的代码,可以像 Twitter 登录输入一样设置 div 的样式。蓝色边框的样式是选择器的box-shadow
和border
样式div[contenteditable]:focus
。现场演示在这里(点击)。
Markup:
标记:
<div contenteditable="true">Username or email</div>
CSS:
CSS:
div[contenteditable]:focus {
border: 1px solid rgb(86, 180, 239);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 8px rgba(82, 168, 236, 0.6);
}
div[contenteditable] {
width: 97%;
max-width: 280px;
margin-right: 10px;
font-family: Arial,sans-serif;
-webkit-box-shadow: inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.075);
box-shadow: inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.075);
display: inline-block;
padding: 4px;
margin: 0;
outline: 0;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 13px;
line-height: 20px;
}
回答by Elliot Bonneville
回答by pshirishreddy
回答by Samwise
As shown before, use css: focus
, border
and box-shadow
.
如前所示,使用 css: focus
、border
和box-shadow
。
If using IE, make sure <doctype>
is specified.
如果使用 IE,请确保<doctype>
已指定。
.text:focus {
border: 1px solid #07c;
box-shadow: 0 0 10px #07c;
}