Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triangle shadow on CSS ribbon

I am trying to replicate http://imgur.com/EutshK1 as pixel perfect as I can get and im having trouble trying to do the shadow on the right. Is this possible with css?

CSS:

*{margin:0px;padding:0px;}

html {
    width:100%;
        height:100%;
      text-align: center;
    }

.bold {
    font-weight:700;
}

#ribbon {
        padding: .34em 1em;
        margin: 0;
        margin-top: 5%;
        position:relative;
        color: #000;
        text-align: center;
        letter-spacing:0.1em;
        padding-top:12px;
        padding-bottom:12px;
        display: inline-block;
        background: #ffd82b;
        z-index:100;
        box-shadow: 0 7px 0px -2px #ebeced;
    }

#ribbon:after {
        content: "";
        width:3.2em;
        bottom:-.5em;
        position:absolute;
        display:block;
        border: .9em solid #ffd82b;
        box-shadow: 0 7px 0px -2px #ebeced;
        z-index:-2;
    }

#ribbon:after {
        right: -4.3em;
        border-left-width: .75em;
        border-right-color:transparent;
    }

#content:after {
        content:"";
        bottom:-.5em;
        position:absolute;
        display:block;
        border-style:solid;
        border-color: #fc9f42 transparent transparent transparent;
        z-index:-1;
    }
#content:before {
    content:"";
        top:-.5em;
    transform: rotate(90deg);
        position:absolute;
        display:block;
        border-style:solid;
        border-color: #fc9f42 transparent transparent transparent;
        z-index:-1;
}

#content:before {
      left: 0;
      border-width: .5em 0 0 .5em;
    }

#content:after {
      right: 0;
      border-width: .5em .5em 0 0;
    }

HTML:

<div id="ribbon">
    <span id="content"><span class="bold">Special Offer:</span> Recieve bonus rewards points for signing up</span>
</div>

Or here's a jsfiddle: http://jsfiddle.net/k0a6jhv6/

like image 503
Luca Avatar asked Mar 10 '15 15:03

Luca


People also ask

How do you put a shadow on a triangle in CSS?

Assuming we're cool with CSS3, one method would be to have a container box with hidden overflow and another box inside it which is rotate and hangs out of it. The part that is still visible would form a triangle. Then you can use a box-shadow on both the boxes to achieve a shadow all the way around.

How do you add shadows to items in CSS?

In CSS, shadows on the boxes of elements are created using the box-shadow property (if you want to add a shadow to the text itself, you need text-shadow ). The box-shadow property takes a number of values: The offset on the x-axis. The offset on the y-axis.

How many types of shadows are there in CSS?

With CSS3 you can create two types of shadows: text-shadow (adds shadow to text) and box-shadow (adds shadow to other elements).

How do you put a shadow on one side in CSS?

h-offset: It is required and used to set the position of the shadow horizontally. The positive value is used to set the shadow on right side of the box and a negative value is used to set the shadow on the left side of the box. v-offset: It is required and used to set the position of shadow vertically.


1 Answers

You can make this ribbon without using box-shadows, only with borders, z-index and pseudo elements :

DEMO

output :

CSS ribbon

.ribbon{
  font-size:20px;
  position:relative;
  display:inline-block;
  margin: 2em 1em;
  text-align:center;
}
.text{
  display:inline-block;
  padding:0.5em 1em;
  min-width:20em;
  line-height:1.2em;
  background: #FFD72A;
  position:relative;
}
.ribbon:after,.ribbon:before,
.text:before,.text:after,
.bold:before{
  content:'';
  position:absolute;
  border-style:solid;
}
.ribbon:before{
  top:0.3em; left:0.2em;
  width:100%; height:100%;
  border:none;
  background:#EBECED;
  z-index:-2;
}
.text:before{
  bottom:100%; left:0;
  border-width: .5em .7em 0 0;
  border-color: transparent #FC9544 transparent transparent;
}
.text:after{
  top:100%; right:0;
  border-width: .5em 2em 0 0;
  border-color: #FC9544 transparent transparent transparent;
}
.ribbon:after, .bold:before{
  top:0.5em;right:-2em;
  border-width: 1.1em 1em 1.1em 3em;
  border-color: #FECC30 transparent #FECC30 #FECC30;
  z-index:-1;
}
.bold:before{
  border-color: #EBECED transparent #EBECED #EBECED;
  top:0.7em;
  right:-2.3em;
}
<p class="ribbon">
  <span class="text"><strong class="bold">Special Offer:</strong> Recieve bonus rewards points for signing up</span>
</p>
like image 76
web-tiki Avatar answered Nov 11 '22 11:11

web-tiki