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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:12:48  来源:igfitidea点击:

glow around div with border and color

csshtml

提问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-shadowand borderstyles for the selector div[contenteditable]:focus. Live demo here (click).

下面是完整的代码,可以像 Twitter 登录输入一样设置 div 的样式。蓝色边框的样式是选择器的box-shadowborder样式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

CSS3can do that

CSS3可以做到

-webkit-box-shadow:0 0 20px blue; 
-moz-box-shadow: 0 0 20px blue; 
box-shadow:0 0 20px blue;

Working JSFiddle.

工作JSFiddle

回答by pshirishreddy

Also you will face some problem with Internet Explorer while dealing this issue. IE-9 How ever supports box-shadow but the previous versions don't, Check it out herefor making it work in all versions of IE

此外,在处理此问题时,您将面临 Internet Explorer 的一些问题。IE-9 如何支持 box-shadow 但以前的版本不支持,请在此处查看以使其适用于所有版本的 IE

回答by Samwise

As shown before, use css: focus, borderand box-shadow.

如前所示,使用 css: focusborderbox-shadow

If using IE, make sure <doctype>is specified.

如果使用 IE,请确保<doctype>已指定。

.text:focus {
    border: 1px solid #07c;
    box-shadow: 0 0 10px #07c;
}

jsFiddle example.

jsFiddle 示例。