创建底部响应箭头

时间:2015-02-12 18:52:24

标签: html css twitter-bootstrap responsive-design css-shapes

我需要使用向下箭头创建网格。见下图:

example

问题是由于.col-xs-3,div的宽度可变。如何给箭头(:after元素)指定适当的宽度,使其仍然具有响应性?

我的CSS

.grid-arrow::after {
    content: " ";
    display: block;
    width: 0;
    height: 0;
    border-top: 47px solid transparent;
    border-bottom: 47px solid transparent;
    border-left: 40px solid rgb(173, 173, 173);
    position: absolute;
    /* top: 50%; */
    margin-top: -37px;
    /* margin-left: 1px; */
    left: 50%;
    z-index: 3;
    -webkit-transform: rotate(90deg);
        -ms-transform: rotate(90deg);
            transform: rotate(90deg);
}

我的HTML

<div class="col-xs-3 advantage grid-arrow">
    <div>
        Some text
    </div>
</div>

1 个答案:

答案 0 :(得分:4)

正如@ochi指出的那样,已经有solution that might work for you

将它带回到您的代码中,它将是这样的:

HTML:

<div class="col-xs-3 advantage grid-arrow">
    <div>
        Some text.
    </div>
</div>

CSS:

.grid-arrow {
    position: relative;
    text-align: center;
    background-color: red;
    line-height: 2em;
    border-top:300px solid #fff;
    top:-300px;
}
.grid-arrow::after {
    content: "";
    position: absolute;
    left: 0;
    background-color: red;
    padding-bottom: 50%;
    width:57.7%;
    z-index:-1;

    -webkit-transform-origin:0 0;
    -ms-transform-origin:0 0;
    transform-origin:0 0;

    -webkit-transform: rotate(-30deg) skewX(30deg);;
    -ms-transform: rotate(-30deg) skewX(30deg);
    transform: rotate(-30deg) skewX(30deg);
}

请参阅JsFiddle