For the record, this kind of effect is usually called "Ribbon", as it resembles a gift tie, box or similar use
It will not be enough to just rotate a DIV, we will have to "trim it", IE, we will have to create a main element, only use ::before
and ::after
won’t work.
To rotate we’ll use
transform: rotate(45deg);
To avoid Ribbon affecting the other elements we will use when clicking or selecting some text or element, because the main element gets bigger than Ribbon, even if you can’t "see it":
pointer-events: none;
Restores events in Ribbon content
pointer-events: auto;
And the "main", to trim the Ribbon we will use:
overflow: hidden;
The element will have to be something like:
<div class="seu-elemento">
<div class="ribbon">
<div class="ribbon-content">Novo</div>
</div>
</div>
Note that the seu-elemento
refers to the element you want to apply, it needs to receive:
position: relative;
The effect should be like this:
Note: this way works even in the Internet Explorer 9
.ribbon {
position: absolute;
right: 0;
top: 0;
width: 100px;
height: 100px;
overflow: hidden;
pointer-events: none; /* impede que o ribbon atrapalhe outros elementos*/
}
.ribbon > .ribbon-content {
position: relative;
top: 15px;
padding: 5px 0;
background-color: #f00;
width: 150%;
transform: rotate(45deg);
text-align: center;
box-shadow: 1px 1px 1px rgba(0,0,0,.5);
pointer-events: auto; /* restaura os eventos somente para o conteudo */
}
/* efeitos somente para teste*/
body {
background: #cfcfcf;
}
.seu-elemento {
position: relative;
width: 200px;
height: 400px;
background: #fff;
float: left;
margin-right: 10px;
margin-bottom: 10px;
}
<div class="seu-elemento">
<div class="ribbon">
<div class="ribbon-content">Novo</div>
</div>
</div>
<div class="seu-elemento">
<div class="ribbon">
<div class="ribbon-content">Novo</div>
</div>
</div>
<div class="seu-elemento">
<div class="ribbon">
<div class="ribbon-content">Novo</div>
</div>
</div>
Young man, I preferred to remove the answer for now that it’s become clear what you want. Then I try to answer you with an option and edit the response I removed
– hugocsl
quiet, thanks...
– Leonardo Bonetti
Ok restored response after a look
– hugocsl