Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a ribbon shape in CSS

http://jsfiddle.net/6HyjZ/

.bookmarkRibbon{
     width:0; 
     height:100px; 
     border-right:50px solid blue;
     border-left:50px solid blue;
     border-bottom:30px solid transparent;
}

<div class="bookmarkRibbon"></div>

I'm struggling to make a version of this shape where the ribbon is pointing right instead of down, how can I achieve this?

like image 266
user3531149 Avatar asked Jun 13 '14 14:06

user3531149


People also ask

How do you make an arrow shape in CSS?

Arrows. To create a simple arrow without a tail, make a box with a width and height, border, as well as zero left and top borders. To make an up arrow, add the transform: rotate(225deg); property, and to make a down arrow, add the transform: rotate(45deg); property to rotate the arrow to 225 and 45 degrees respectively ...


2 Answers

To help you visualize the logic step-by-step
so you can apply it easily on ANY SIDE you desire:

CSS Ribbon Shape - How To Create

.bookmarkRibbon {
  border:       50px solid blue;        /* All borders set */
  border-left:  0;                      /* Remove left border */
  border-right: 30px solid transparent; /* Right transparent */
  width:        100px;                  /* Increase element Width */
}
<div class="bookmarkRibbon"></div>
like image 80
Roko C. Buljan Avatar answered Sep 18 '22 20:09

Roko C. Buljan


Using the helpful accepted answer here is it with text version.

Vertical(Top to bottom) Banner with text

.ribbon-vertical {
	position: absolute;
	right: 10px;
  	border:       13px solid #e46a76;        /* All borders set */
  	border-top:  0;                      /* Remove left border */
  	border-bottom: 10px solid transparent; /* Right transparent */
  	height: auto;                  /* Increase element Width */
  	width: 0;
  	word-wrap: break-word;
  	color: white;
  	z-index: 1;
  	-webkit-filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    		filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.ribbon-vertical div{
    position: relative;
    right: 5px;
    padding-top: 2px;
    padding-bottom: 2px;
}
<div class="ribbon-vertical"><div>BANNER</div></div>

Horizontal(Right to Left) Banner with text

.ribbon-horizontal{
	position: absolute;
	right: 0;
	bottom: 5rem;
  	border: 13px solid #e46a76;
  	border-right: 0;
  	border-left: 10px solid transparent;
  	height: 0;
  	line-height: 0;
  	width: 100px;
  	color: white;
  	z-index: 1;
  	-webkit-filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
    		filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
	letter-spacing: 3px;
}
.ribbon-horizontal span{
	position: relative;
	padding: 0 4px 0 10px;
	text-align: center;   			
}
<div class="ribbon-horizontal"><span>BANNER</span></div>
like image 28
MR_AMDEV Avatar answered Sep 19 '22 20:09

MR_AMDEV