创建一个带边框的元素,“缝合”到内部对象的外边框

时间:2012-11-29 13:01:37

标签: html css

将div(或其他元素)用边框“缝合”到div中对象的外边框的方法是什么?

例如:example

1 个答案:

答案 0 :(得分:2)

如果您只想使用css并且没有任何javascript插件,那么您可以通过大量工作来完成,例如: Demo

HTML

<div id="main">
    <div class="red"><div class="content">Red</div></div>
    <div class="green"><div class="content">Green</div></div>
    <div class="blue"><div class="content">Blue</div></div>
    <div class="black"><div class="content">Black</div></div>
</div>

CSS

#main {position:relative;}
.black, .red, .blue, .green {
    position:absolute;
    border:3px dotted #000;
    background:#FFF;
    z-index:10;
}
.content {position:relative;margin:10px;}
.black {top:300px;left:103px;z-index:9;}
.black .content {height:180px;width:280px;background:#000;}
.blue{ top:50px;left:200px;border-bottom:none;}
.blue .content {height:30px;width:30px;background:#009;}
.red{top:0px;left:0px;}
.red .content {height:280px;width:80px;background:#F00;}
.green{top:100px;left:103px;border-left:none;border-bottom:none;}
.green .content{height:180px;width:180px;background:#070;}

在这里,您需要设置每个元素的位置及其大小,然后您必须针对每个叠加边框的每个显示进行调整。

这有点难看,但那有效......