【问题标题】:Hollow arrow in front of an image [duplicate]图像前面的空心箭头 [重复]
【发布时间】:2014-11-02 13:35:17
【问题描述】:

我正在尝试在图像前面创建一个空心 css 箭头。

我明白了……但感觉很脏。有没有更好的方法来做到这一点? 跨浏览器兼容性(IE8+)会很棒。

SCSS

.arrowwrap {
    width:100%;
    padding:0;
    position:relative;
    overflow:hidden;
    margin:-$arrow_height 0 0 0;
    &:after {
        content:'';
        position:absolute;
        height:$arrow_height;
        width:50%;
        margin:-$arrow_height 0 0 -$arrow_width;
        left:0;
        z-index:99999;
        background:$box_color;
    }
    &:before {
        content:'';
        position:absolute;
        height:$arrow_height;
        width:100%;
        left:50%;
        margin:0 0 0 $arrow_width;
        z-index:99999;
        background:$box_color;
    }
    .arrowone {
        width: 0;
        height: 0;
        border-style: solid;
        border-width: $arrow_height $arrow_width 0 $arrow_width;
        /* border-color: transparent transparent #333 transparent; */
        border-color:transparent $box_color $box_color $box_color;
        margin:auto;
    }
}

http://jsfiddle.net/dhs2eba2/

【问题讨论】:

标签: html css sass css-shapes


【解决方案1】:

不确定 IE8,我的 VM 上没有副本,但您可以这样处理它而不是伪元素

<div class="arrowborder">
    <div class="arrrowwrap arrowwrapleft"></div>
    <div class="arrrowwrap arrowwrapright"></div>
</div>

.arrrowwrap {
    box-sizing:border-box;
    width:50%;
    z-index:9999999;
    float:left;
}
.arrowwrapleft {
    border-right: $arrow_width solid transparent; 
    border-bottom: $arrow_height solid $box_color;
}
.arrowwrapright {
    border-left: $arrow_width solid transparent; 
    border-bottom: $arrow_height solid $box_color;
}

http://jsfiddle.net/dhs2eba2/8/

【讨论】:

    【解决方案2】:

    如果您想最小化并删除所有无语义标记,您可以这样做:

    DEMO

    这种技术依赖于伪元素,因此可以防止使用无语义标记。 IE8+ 支持伪元素,请参阅canIuse。它还需要box-sizing 属性来启用响应宽度(IE8+ 也支持box-sizing: border-box,请参阅canIuse)。

    HTML:

    <div class="wrap">
        <img src="http://placekitten.com/800/350" />
        <article>
            <h1>Hellow World, meow</h1>
        </article>
    </div>
    

    CSS:

    body {
        background:#fad;
        padding:0;
        margin:0;
    }
    
    $arrow_width: 20px;
    $arrow_height: 20px;
    $box_color: #d3d030;
    
    .wrap {
        img {
            width:100%;
            height:auto;
            vertical-align:bottom;
        }
        article{
            padding:20px;
            background:$box_color;
            color:#fff;
            position:relative;
        }
    }
    article:before, article:after{
        content:'';
        position:absolute;
        width:50%;
        bottom:100%;
        box-sizing:border-box;
    }
    article:before{
        left:0;
        border-bottom:20px solid #D3D030;
        border-right:20px solid transparent;
    }
    article:after{
        right:0;
        border-bottom:20px solid #D3D030;
        border-left:20px solid transparent;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 2016-07-04
      • 2020-02-25
      • 2019-06-02
      • 2011-07-18
      • 2012-07-14
      • 1970-01-01
      相关资源
      最近更新 更多