如何在这个8点星外面添加红色边框?或者有没有人知道的简单的svg解决方案?
HTML
<div id="star8"></div>
CSS
#star8 {
border: 3px solid red;
background: blue; width: 80px;
height: 80px;
position: relative;
-webkit-transform: rotate(20deg);
-moz-transform: rotate(20deg);
-ms-transform: rotate(20deg);
-o-transform: rotate(20eg);
}
#star8:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: blue;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
}
答案 0 :(得分:6)
您可以使用mix-blend-mode,最终使用其他伪: DEMO
#star8:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
transform: rotate(135deg);
box-shadow: 0 0 0 3px red;::* a border works too */
mix-blend-mode:overlay;
}
#star8 {
margin: 2em;
border: 3px solid red;
background: blue;
width: 80px;
height: 80px;
position: relative;
transform: rotate(20deg);
}
#star8:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: blue;
transform: rotate(135deg);
}
#star8:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
transform: rotate(135deg);
box-shadow: 0 0 0 3px red;
mix-blend-mode:overlay;
}
<div id="star8"></div>
没有mix-blend-mode
但z-index
和:after
#star8 {
margin: 2em;
border: 3px solid red;
background: blue;
width: 80px;
height: 80px;
position: relative;
transform: rotate(20deg);
}
#star8:before {
content: "";
position: absolute;
z-index:-1;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: blue;
transform: rotate(135deg);
box-shadow: 0 0 0 3px red;
}
#star8:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: blue;
transform: rotate(0deg);
}
<div id="star8"></div>
linear-gradient
)来隐藏不需要的边框部分并在其中添加一些文字:http://codepen.io/gc-nomade/pen/KWNmqw
答案 1 :(得分:6)
可以使用单个svg路径创建。 添加轮廓可以通过向路径添加笔划属性来完成
<svg viewBox="-1 -1 50 50" width="200px">
<path d="M 35,40 30,48 21,42 11,44 9,34 0,30 6,20 4,10 14,8 20,0 28,5 38,3 l 1,10 8,5 -5,8 2,10z" stroke="red" stroke-linejoin="bevel" fill="black" />
</svg>
&#13;
答案 2 :(得分:2)
div看起来像现在这样的原因是你实际上没有一个8角星,你有2个方格叠加在一起。
第一步是将大纲添加到:before伪类之前。第二个是添加:在没有轮廓的伪类之后,旋转到与原始div相同的位置,以覆盖绘制的轮廓:在重叠原始div之前。
演示:https://jsfiddle.net/hj1eh6md/
和CSS:
#star8 {
border: 3px solid red;
background: olive;
width: 80px;
height: 80px;
position: relative;
-webkit-transform: rotate(20deg);
-moz-transform: rotate(20deg);
-ms-transform: rotate(20deg);
-o-transform: rotate(20eg);
}
#star8:before {
border: 3px solid red;
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: olive;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
}
#star8:after{
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: olive;
}
答案 3 :(得分:0)
在其上覆盖另一个矩形:之后,遮住红色边框。 http://codepen.io/anon/pen/qbrQZa
#star8:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 80px;
width: 80px;
background: blue;
}
您还应该使#star8:before
的大小仅为77x77,以使其适合。