How to create a ribbon shape in CSS

前端 未结 8 840
旧时难觅i
旧时难觅i 2021-01-05 15:00

http://jsfiddle.net/6HyjZ/

.bookmarkRibbon{
     width:0; 
     height:100px; 
     border-right:50px solid blue;
     border-left:50px solid blue;
     bord         


        
相关标签:
8条回答
  • 2021-01-05 15:16

    Just swap what you have and you are good to go jsfiddle:

    .bookmarkRibbonRight{
         width:100px; 
         height:0px; 
         border-right:30px solid transparent;
         border-bottom:50px solid blue;
         border-top:50px solid blue;
    }
    
    0 讨论(0)
  • 2021-01-05 15:19

    Use transform:rotate :

    .bookmarkRibbon{
         width:0; 
         height:100px; 
         border-right:50px solid blue;
         border-left:50px solid blue;
         border-bottom:30px solid transparent;
        transform:rotate(7deg);
        -ms-transform:rotate(7deg); /* IE 9 */
        -webkit-transform:rotate(7deg); /* Opera, Chrome, and Safari */
    }
    
    0 讨论(0)
  • 2021-01-05 15:21

    Use the rotate css transform:

     .bookmarkRibbon{
          width:0; 
          height:100px; 
          border-right:50px solid blue;
          border-left:50px solid blue;
          border-bottom:30px solid transparent;
         -webkit-transform: rotate(90deg);
         -ms-transform: rotate(90deg);
         transform: rotate(90deg);
     }
    

    http://jsfiddle.net/6HyjZ/13/

    0 讨论(0)
  • 2021-01-05 15:22

    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>

    0 讨论(0)
  • 2021-01-05 15:24

    If you 'rotate' the css properties, it rotates the form by 90 degrees.

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

    http://jsfiddle.net/6HyjZ/6/

    0 讨论(0)
  • 2021-01-05 15:27

    You already have the shape, just use the transform property to change its angle.

    Here is the code that I have added to the code you have.

     transform: rotate(270deg);
    

    Here is the fiddle, http://jsfiddle.net/6HyjZ/11/ It now points to the right (unless that's right right side)

    0 讨论(0)
提交回复
热议问题