我有由4个“互锁” div的一个布局,像这样:

-------**********
-     -*        *
-     -*        *
-     -*        *
-------         *
++++++ *        *
+    + *        *
+    + **********
+    + ^^^^^^^^^^
+    + ^        ^
+    + ^        ^
+    + ^        ^
+    + ^        ^
++++++ ^^^^^^^^^^

我要加边框的“顶”和“底”位,有最终的布局是这样的:

-------**********
-               *
-               *
-               *
-------         *
++++++ *        *
+    + *        *
+    + **********
+    +^^^^^^^^^^^
+               ^
+               ^
+               ^
+               ^
++++++^^^^^^^^^^^

(当使用时,以满足两个div应平稳边界看起来像一个统一形状)

我应该怎么做这个正确的CSS?

有帮助吗?

解决方案

这里是我的解决方案。的它使用花车与阴性切缘和假货无边界由边界设置到div的背景色部分。

.w {width:223px;}
.box {float:left;height:100px;width:100px;border:1px solid #000;margin-bottom:10px;}
.tall {height: 300px;}
.wide {width:120px;}
.right {position:relative;z-index:1;float:right;margin-left:-1px;}
.no_rb {border-right:1px solid #fff;position:relative;z-index:10;}
.no_lb {border-left:1px solid #fff;position:relative;z-index:10;}

<div class="w">
    <div class="box wide no_rb"></div>
    <div class="box tall right"></div>
    <div class="box tall"></div>
    <div class="box right wide no_lb"></div>
</div>

其他提示

可以做的绝对定位的div此1px的边界和1px的重叠。有申报单的小对于给定的相交没有边界,并使其重叠较大div的边界。

编辑:此外,较小的div应具有较高的z索引所以它搁置在顶

这只是一个打了一下有边框,填充和相对定位问题。看到这个例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>DIVs</title>
    <style type="text/css">
        body, html {
            background: #eee;
        }

        div.box {
            background: #fff;
            border-style: solid;
            border-width: 2px;
            position: relative;
            width: 100px;
            z-index: 1;
        }

        div.group {
            float: left;
        }

        #box-1, #box-4 {
            z-index: 2;
        }

        #box-1 {
            border-color: #f00;
            border-bottom: 0;
            border-right: 0;
            padding-right: 2px;
        }

        #box-2 {
            border-color: #f0f;
        }

        #box-3 {
            border-color: #0f0;
        }

        #box-4 {
            border-color: #00f;
            border-left: 0;
            border-top: 0;
            padding-left: 2px;
        }

        #group-2 {
            left: -2px;
            position: relative;
        }
    </style>
</head>
<body>
<div class="group" id="group-1">
    <div class="box" id="box-1">one<br />one<br />one<br />one</div>
    <div class="box" id="box-2">two<br />two<br />two<br />two<br />two<br />
    two</div>
</div>
<div class="group" id="group-2">
    <div class="box" id="box-3">three<br />three<br />three<br />three<br />
    three<br />three</div>
    <div class="box" id="box-4">four<br />four<br />four</div>
</div>
</body>
</html>

尝试这一个。使用浮筒,负边缘和z索引仅

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>Interlock test</title>
        <style>
            div { width:150px; border:1px solid #000; background:#fff; position:relative; margin-bottom:5px; float:left; }
            .container { width:309px; border:none; }
            .tallTop, .tallBottom { height:400px; z-index:1; }
            .tallTop { float:right; }
            .shortTop, .shortBottom { height:200px; z-index:2; width:157px; }
            .shortTop { margin-right:-1px; border-right:none; }
            .shortBottom { margin-left:-1px; border-left:none; float:right; }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="shortTop"></div>
            <div class="tallTop"></div>
            <div class="tallBottom"></div>
            <div class="shortBottom"></div>
        </div>
    </body>
</html>

什么你问在单独地使用CSS任何跨浏览器兼容的方式是不可能的。你需要肯定使用JavaScript这一点。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top