【问题标题】:Left-bottom border左下边框
【发布时间】:2012-02-17 07:35:08
【问题描述】:

想象一下(或者如果你无法想象,请观看)这段代码:

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

现在看看底线。这是我的问题;我希望左右边框长 1px(所以底部边框是左右边框之间的部分)。
有可能做到这一点吗?

【问题讨论】:

    标签: html css border


    【解决方案1】:

    这是一种方法,因为盒子模型不支持你需要的,只使用一个div:

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

    和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;
    }
    

    这会将左右两边的黑色边框延长1px。

    【讨论】:

      【解决方案2】:

      【讨论】:

        【解决方案3】:

        如果您有两个容器,一个用于外部左/右边框,一个用于内部底部边框,则这是可能的。我已经整理了一个演示来展示这一点。

        演示: 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>
        

        【讨论】:

          【解决方案4】:

          通过此策略,无需在 HTML 中添加任何无关元素即可完成:

          .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;
          }
          

          伪元素 :before 仅支持 IE8,但适用于所有其他主流浏览器。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-09-02
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-15
            • 2016-09-26
            • 1970-01-01
            • 2019-01-06
            相关资源
            最近更新 更多