2011-07-04 163 views
0

我发现了几篇关于如何确定边框的文章,但我试图做的是有点不同。CSS虚线和斜线边框

我有虚线边框的元素,像这样:

.box { border: 1px dashed #fff; } 

不过,我试图同时拥有.box的元素及其虚线边框的边角成45度角。

这可能吗?

+0

所以你想“边缘”而不是破折号?或者你想整个盒子(和边框)旋转45度? –

+0

我希望整个边界都是虚线,但是每个角都要成45度角,包括虚线。 – gjunkie

回答

0

是否有一个原因,为什么你会不想与2背景元素做到这一点?

.box { 
    /* this background image will stick to the top of the box */ 
    background: url(/* you would put a 10px high image that is the width of said box */) no-repeat left top; 
    display: block; 
    padding: 10px 0 0; /* this padding element needs to match the background height */ 
} 
    .box .inner { 
     /* this will stick the background image to the bottom, and grow with the natural height of the box */ 
     background: url(/* you'd put a looong background image, that could stretch vertically */) no-repeat left bottom; 
     display: block; 
     padding: 0 10px 10px; 
    } 

您的标记应该是这样的:

<div class="box"> 
    <div class="inner"> 
     ...Content goes here... 
    </div> 
</div> 

我能理解,如果你想只用border风格做到这一点,但我不知道的方式做正确的角度和让它在IE中工作,要获得最大的认可。

+0

感谢您的帮助。我想这样做的原因是因为我试图用虚线在博客文章周围有一个包裹元素,并且在它下面有一个看起来像这样的选项卡。如果我用图像制作破折号,那么匹配CSS生成的破折号将会更困难。 – gjunkie