1

I need to create grid with a down arrow. See the image below:

example

The problem is that the div has a variable width because of .col-xs-3. How can I give the arrow (:after element) the appropriate width so that it will still be responsive?

My 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);
}

My HTML:

<div class="col-xs-3 advantage grid-arrow">
    <div>
        Some text
    </div>
</div>
web-tiki
  • 99,765
  • 32
  • 217
  • 249
GO VEGAN
  • 1,113
  • 3
  • 15
  • 44
  • can you use a background image aligned to the bottom instead? (and leave a bottom padding large enough) or does it have to be done strictly in CSS? – blurfus Feb 12 '15 at 18:55
  • I really prefer css if there is good solution.. – GO VEGAN Feb 12 '15 at 19:11
  • See if this answer helps: http://stackoverflow.com/questions/25360411/responsive-css-triangle-with-percents-width – blurfus Feb 12 '15 at 19:23
  • JsFiddle of OP's case: http://jsfiddle.net/fhzv3mmf/ – falsarella Feb 12 '15 at 21:36
  • I've made a working fiddle based on @ochi's recommendation link: http://jsfiddle.net/fhzv3mmf/2/ If it is fine for you, this question is a duplicate. – falsarella Feb 12 '15 at 22:05

1 Answers1

4

As pointed out by @ochi, there is already a solution that might work for you.

Bringing it back to your code, it would be something like this:

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

See JsFiddle.

Community
  • 1
  • 1
falsarella
  • 12,217
  • 9
  • 69
  • 115