开发者

Left-bottom border

开发者_Go百科Imagine (or if you can't imagine, watch) this piece of code:

<div class="block"></div>
<style>
  .block {
    width: 10px;
    height: 10px;
    display: block;
    background-color: red;
    border: 1px solid #000000;
    border-bottom: 0;
}
</style>

Now look at the bottom line. This is my problem; I want the left and right border to be 1px longer (so the bottom border is the part between the left border and right border).

Is it possible to accomplish this??


This is a way to do it, since the box model does not support what you need, using only one div:

<div class="block"><div></div></div>

and the css:

.block {
    width: 10px;
    height: 10px;
    border: 1px solid #000000;
    border-bottom: 0;
    padding-bottom: 1px;
}

.block div {
    width: 10px;
    height: 10px;
    background-color: red;
}

This will extend the black border on the left and right side with 1px.


Try this :) http://jsfiddle.net/z6ASC/


This is possible if you have two containers, one for the outside left/right borders, and one for the inside bottom-border. I've put together a demo showing this.

DEMO: http://wecodesign.com/demos/stackoverflow-7074782.htm

<style type="text/css">
#borderOutside {
    height: 200px;
    width: 300px;
    border:1px solid #900;
    border-bottom: none;    
    padding-bottom: 5px; /*this is the gap at the bottom*/
}
#borderInside {
    height: 100%;
    border-bottom: 1px solid #900;
}
</style>
<div id="borderOutside">
    <div id="borderInside"><!--Your Content--></div>
</div>


It can be done without adding any extraneous elements in your HTML via this strategy:

.block {
  position: relative;
  width: 10px;
  height: 10px;
  display: block;
  background-color: red;
}

.block:before {
  position: absolute;      
  content: '';
  width: 10px;
  height: 11px;
  top: -1px;
  left: -1px;
  border: 1px solid #000;
  border-bottom: none;
}

The pseudo element :before is only supported from IE8, but works in all other major browsers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜