[英]Create highlight around div element where highlight elements have white fill and colored border
The goal is to highlight the border of a div, and allow this highlighting to be visible no matter the underlying colors. 目的是突出显示div的边框,并且无论基础颜色如何,都可以看到该突出显示。 The thought was to achieve this by creating a border around the div where each border element (in this case circles, not dashes) contains a white fill and itself a colored border.
想法是通过在div周围创建一个边框来实现此目的,其中每个边框元素(在本例中为圆形,而不是破折号)都包含白色填充,而其自身是彩色边框。
Unfortunately, the borders don't overlap and are instead offset, which generates a two-border look instead of a single border with different colors. 不幸的是,边界不重叠,而是偏移,这会生成两边界外观,而不是具有不同颜色的单个边界。
Codepen: https://codepen.io/anon/pen/gqbrzv Codepen: https ://codepen.io/anon/pen/gqbrzv
<div class="selectionBox">
<div class="inner"></div>
</div>
.selectionBox {
width: 100px;
height: 100px;
background: blue;
box-sizing: border-box;
position: absolute;
border: 5px dotted #FFF;
pointer-events: none;
}
.selectionBox .inner {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 7px dotted #F23C32;
}
You can consider radial gradient to achieve this: 您可以考虑使用径向渐变来实现此目的:
.selectionBox { width: 100px; height: 100px; padding: 10px; background: linear-gradient(blue,blue) content-box, /*will hide the radial gradient inside and keep them only visible on the padding*/ radial-gradient(#fff 40%,red 44%,red 58%,transparent 60%) top left/10px 10px, blue; box-sizing: border-box; position: absolute; pointer-events: none; }
<div class="selectionBox"> </div>
If you have an absolute element, it will always be positioned according to the first parent that's relative, and if this has a border, it will offset according to that. 如果您有一个绝对元素,它将始终根据相对的第一个父元素进行定位,如果有一个边界,它将根据该元素进行偏移。 My solution involves putting both selectionBox and inner within an absolutely positioned container, and then making these elements the same size, except the inner element has red dots:
我的解决方案包括将selectionBox和inner放入一个绝对定位的容器中,然后使这些元素具有相同的大小,但inner元素具有红点:
.container { position: relative; } .selectionBox { width: 100px; height: 100px; background: blue; box-sizing: border-box; position: absolute; top: 0; left: 0; border: 7px dotted #FFF; pointer-events: none; } .inner { position: absolute; top: 0; left: 0; width: 100px; height: 100px; box-sizing: border-box; border: 7px dotted #F23C32; }
<div> <div class="selectionBox"> </div> <div class="inner"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.