How to create a ribbon shape in CSS

2019-05-27 03:00发布

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?

7条回答
该账号已被封号
2楼-- · 2019-05-27 03:23

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/

查看更多
孤傲高冷的网名
3楼-- · 2019-05-27 03:26

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/

查看更多
Anthone
4楼-- · 2019-05-27 03:33

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 */
}
查看更多
The star\"
5楼-- · 2019-05-27 03:34
.bookmarkRibbon{
     width:100px; 
     height:0; 
     border-bottom:50px solid blue;
     border-top:50px solid blue;
     border-right:30px solid transparent;
}
查看更多
孤傲高冷的网名
6楼-- · 2019-05-27 03:44

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;
}
查看更多
Melony?
7楼-- · 2019-05-27 03:44

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)

查看更多
登录 后发表回答