我需要创建一个纯色镶嵌边框.这是我正在使用的一小段CSS:

border: 10px inset rgba(51,153,0,0.65);

不幸的是,这会创建一个3D隆起的边框(忽略方框和黑色描述框)

推荐答案

你可以用box-shadow,可能是:

#something {
    background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
    min-width: 300px;
    min-height: 300px;
    box-shadow: inset 0 0 10px #0f0;
}

#something {
  background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
  min-width: 300px;
  min-height: 300px;
  box-shadow: inset 0 0 10px #0f0;
}
<div id="something"></div>

这样做的优点是它将覆盖div的背景图像,但它当然是模糊的(正如您从box-shadow属性中预期的那样).要构建阴影的density,当然可以添加其他阴影:

#something {
    background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
    min-width: 300px;
    min-height: 300px;
    box-shadow: inset 0 0 20px #0f0, inset 0 0 20px #0f0, inset 0 0 20px #0f0;
}

#something {
  background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
  min-width: 300px;
  min-height: 300px;
  box-shadow: inset 0 0 20px #0f0, inset 0 0 20px #0f0, inset 0 0 20px #0f0;
}
<div id="something"></div>


Edited是因为我意识到自己是个白痴,忘了提供最简单的解决方案first,即使用一个否则为空的子元素在背景上应用边框:

#something {
  background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
  min-width: 300px;
  min-height: 300px;
  padding: 0;
  position: relative;
}
#something div {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 10px solid rgba(0, 255, 0, 0.6);
}
<div id="something">
  <div></div>
</div>


@CoryDanielson's comment, below后的Edited:

JSFIDLE.net/dPcDu/2您可以为box-shadow添加第四个px参数,该参数进行传播,并更容易反映他的图像.

#something {
  background: transparent url(https://i.stack.imgur.com/RL5UH.png) 50% 50% no-repeat;
  min-width: 300px;
  min-height: 300px;
  box-shadow: inset 0 0 0 10px rgba(0, 255, 0, 0.5);
}
<div id="something"></div>

Css相关问答推荐

如何将bslib::card()中的扩展按钮移到右上方,其中full_screen = TRUE?

使用背景滤镜时,伪元素出现在div之前

Safari CSS扫描动画效果不起作用

如何在CSS中实现边框的局部透明?

如何使按钮:之后像按钮:之前一样可见

动态覆盖 Vuetify 类

.SVG 文件对象在锚标签下可点击

应用填充时边框无法正常工作

Mat table - 保留第一列和复选框

如何在真实文本旁边制作文本阴影,使其看起来像 css 中的重复文本?

如何在 TypeScript 文件中导入 CSS 模块?

我无法在 next.js 应用程序中传播 daisyui 的主题

如何应用适当样式的元素加消息框?

CSS 常量()用于什么?

紫色表示访问过的超链接

在所有移动设备中禁用滚动

删除在 ios safari / chrome / firefox 中单击的链接上的灰色背景

单击时 HTML 输入字段未获得焦点

边界半径应该剪辑内容吗?

为什么对 HTML 表单而不是表格使用定义列表(DL、DD、DT)标签?