答案 0 :(得分:34)
看看这个,我们可以使用outline-offset
属性
输出图片看起来像
.black_box {
width:500px;
height:200px;
background:#000;
float:left;
border:2px solid #000;
outline: 1px dashed #fff;
outline-offset: -10px;
}

<div class="black_box"></div>
&#13;
答案 1 :(得分:4)
dashed
边框样式进行大纲。background-color
或:before
伪元素绘制:after
。注意: 此方法可让您获得最大的浏览器支持。
输出图片:
* {box-sizing: border-box;}
.box {
border: 1px dashed #fff;
position: relative;
height: 160px;
width: 350px;
margin: 20px;
}
.box:before {
position: absolute;
background: black;
content: '';
bottom: -10px;
right: -10px;
left: -10px;
top: -10px;
z-index: -1;
}
&#13;
<div class="box">
</div>
&#13;
答案 2 :(得分:2)
HTML:
<div class="outerDiv">
<div class="innerDiv">Content</div>
</div>
CSS:
.outerDiv{
background: #000;
padding: 10px;
}
.innerDiv{
border: 2px dashed #fff;
min-height: 200px; //adding min-height as there is no content inside
}
答案 3 :(得分:2)
请看看
"graphs": [
// other graphs omitted
{
"showBalloon": false, //ensures that no balloon is displayed
"visibleInLegend": false, //ensures that this graph is not displayed in the legend
"lineAlpha": 0, //hides the line
"labelText": "[[value]]", //required for the labelFunction
"labelFunction": function(graphDataItem, valueText) { //calculates the percent and displays the label
return ((graphDataItem.dataContext.columnTotal / graphDataItem.dataContext.dataTotal) * 100).toFixed(2) + "%";
},
"valueField": "columnTotal"
}
]
答案 4 :(得分:1)
IE不支持outline-offset,因此另一种解决方案是创建2个div标签,一个嵌套到另一个标签中。内部有一个边框,略小于容器。
.container {
position: relative;
overflow: hidden;
width: 400px;
height: 100px;
background: #000000;
padding: 10px;
}
.inner {
position: relative;
overflow: hidden;
width: 100%;
height: 100%;
background: #000000;
border: 1px dashed #ffffff;
}
&#13;
<div class="container">
<div class="inner"></div>
</div>
&#13;
答案 5 :(得分:1)
.blackBox {
width: 100%;
height: 200px;
background-color: #000;
position: relative;
color: cyan;
padding: 20px;
box-sizing: border-box;
}
.blackBox::before {
position: absolute;
border: 1px dotted #fff;
left: 10px;
right: 10px;
top: 10px;
bottom: 10px;
content: "";
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="blackBox">Created an inner border box. <br> Working fine all major browsers.</div>
</body>
</html>
答案 6 :(得分:1)
您也可以使用box-shadow
并通过border
为虚线background-clip
添加透明度,以便您看到body
background
。
例如
h1 {
text-align: center;
margin: auto;
box-shadow: 0 0 0 5px #1761A2;
border: dashed 3px #1761A2;
background: linear-gradient(#1761A2, #1761A2) no-repeat;
background-clip: border-box;
font-size: 2.5em;
text-shadow: 0 0 2px white, 0 0 2px white, 0 0 2px white, 0 0 2px white, 0 0 2px white;
font-size: 2.5em;
min-width: 12em;
}
body {
background: linear-gradient(to bottom left, yellow, gray, tomato, purple, lime, yellow, gray, tomato, purple, lime, yellow, gray, tomato, purple, lime);
height: 100vh;
margin: 0;
display: flex;
}
::first-line {
color: white;
text-transform: uppercase;
font-size: 0.7em;
text-shadow: 0 0
}
code {
color: tomato;
text-transform: uppercase;
text-shadow: 0 0;
}
em {
mix-blend-mode: screen;
text-shadow: 0 0 2px white, 0 0 2px white, 0 0 2px white, 0 0 2px white, 0 0 2px white
}
<h1>transparent dashed border<br/>
<em>with</em> <code>background-clip</code>
</h1>