2014-05-08 65 views
1

我正在尝试创建一个半径边框,但不是用纯色的样式,而是用虚线的样式。如何用css创建虚线半径边框?

这是demo这是固体风格,但我希望它是破风格。

div{ 
    width: 200px; 
    height: 200px; 
    border: 2px dashed; 
    position: relative; 
} 
div:after{ 
    content: ""; 
    width: 25px; 
    height: 25px; 
    position: absolute; 
    z-index: 2; 
    top: 15px; 
    right: -29px; 
    border-top: 2px dashed; 
    border-left: 2px solid #fff; 
    border-right: 2px dashed; 
    border-bottom: 2px dashed; 
    border-radius: 0 25px 0 0; 
} 

enter image description here


更新:

它的工作在Chrome和IE太多,但不能在Firefox,而我使用的Firefox版本28.

+0

它已经破灭了,男人。 – mayankcpdixit

+0

检查后伪元素:) –

+0

嗨,它只是破折号。你的意思是点缀风格..请检查链接演示http://jsfiddle.net/smey7/2/ – Renjith

回答

2

如果你的小盒子不能容纳任何内容,你可以使用另一个伪元素来创建一个掩码。 DEMO

div:before { 
    content: ""; 
    width: 10px; 
    height: 10px; 
    position: absolute; 
    z-index: 3; 
    top: 15px; 
    right: -29px; 
    border-radius:100%; 
    box-shadow:inset 0 0 0 5px white, 0 0 0 5px white;; 
    border:solid transparent 5px; 
} 

其实,这将是更好的只会这mozillas浏览器:DEMO

@-moz-document url-prefix() { 
    div:before { 
    content: ""; 
    width: 10px; 
    height: 10px; 
    position: absolute; 
    z-index: 3; 
    top: 15px; 
    right: -29px; 
    border-radius:100%; 
    box-shadow:inset 0 0 0 5px white, 0 0 0 5px white;; 
    border:solid transparent 5px; 
} 
} 
+0

否则,SVG会正常工作。 –

2

可悲的是,它听起来像一个Firefox中的错误:

bugzilla 382721

,这意味着你将不得不使用的图像或东西,使它看起来像它在Chrome一样。很烦人。

尝试去为这个LNK http://www.css3.info/preview/border-image/

请注意,我不能担保是否是绝对有可能利用边界图像达到你想要的效果,但是现在看来似乎可能。

+0

尝试并为其提供解决方案。不是没有工作的原因。 – SSS

+0

那么我对这个问题的回答是,你不能在Firefox中提供虚线的边界半径,因为这个错误。对于被问及“如何用css创建虚线半径边界?”这个问题,这是正确的答案。我不明白你的问题。 – Woody

+0

我没有问题。 :)只是试图帮助我们卡住的朋友 – SSS

0

这是火狐的限制。每种类型的圆角看起来都像是border-style:solid。为了更好的理解你可以检查this的例子。