我怎样才能在中间元素周围有适当的边框?

时间:2012-11-29 12:31:59

标签: css

如何在midItem元素周围设置适当的边框?

http://jsfiddle.net/PmfLm/

这是同一个小提琴的缩小代码,

<!DOCTYPE html>
<meta charset="utf-8"> 
<html>
<head>
    <style type="text/css">
    span,.midItem {
        border-style: solid;
    }
    .midItem {
        border-color: blue;
        padding: 5px;
    }
    p {
        text-align:justify;     
    }
    .leftPage,.rightPage{
        display:inline-block;
        width: 33%;
        padding: 5px;
    }
    .centerBox {
        display:table-cell;
        text-align: center;
        vertical-align: middle;
    }
    .leftBox,.rightBox {
        display: table;
        border-style:dotted; 
        border-width:5px;
        width: 100px;
        height: 100px;
        border-color:green;
    }
    .leftBox,.leftPage {
        float:left; 
    }
    .rightBox,.rightPage {
        float:right; 
    }
    </style>
</head>
<body>
<span class="leftPage"><span class="leftBox"><p class="centerBox">Leftbox</p></span>
<p>Some Text</p>
</span>
<span class="rightPage"><span class="rightBox"><p class="centerBox">rightBox</p></span>
<p>SomeText</p>
</span>
<p class="midItem">SomeText</p>
</body>
</html>

2 个答案:

答案 0 :(得分:2)

没有正确回答你的问题,但是你需要这样的东西吗?如果是,请清除浮动,使用overflow: hidden;作为容器div

Demo

CSS

span,.midItem {
    border-style: solid;
    overflow: hidden;
}

答案 1 :(得分:1)

如果你使用table-cell在所有元素中获得相同的高度,那么你应该将它设置为所有三个元素

.midItem {
    border-color: blue;
    padding: 5px;
    display:table-cell;
}
.leftBox,.leftPage {
    display:table-cell;
}
.rightBox,.rightPage {
    display:table-cell;
}

http://jsfiddle.net/PmfLm/3/