Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS angle a div

Tags:

html

css

I have a div inside another div and I am trying to angle the div so the left side is touch the left side and the right side is touching the top. Is there away to do with CSS?

Here is my code:

.background { 
    background-color:black; 
    height:368px; 
}

.sold { 
    background-color:red; 
    font-size:26px; 
    width:200px; 
    text-align:center; 
    height:40px; 
    color:white; 
    line-height:40px;
}

<div class="background">

<div class="sold">Sold Out</div>

</div>

Here is my jfiddle: http://jsfiddle.net/vakcgvtu/

like image 981
user979331 Avatar asked Oct 16 '14 21:10

user979331


2 Answers

You can use transform for this:

.background {
    background-color:black;
    height:368px;
    position: relative;
    overflow: hidden;
}
.sold {
    background-color:red;
    font-size:26px;
    width:200px;
    text-align:center;
    height:40px;
    color:white;
    line-height:40px;
    -webkit-transform: rotate(-45deg);
    -ms-transform: rotate(-45deg);
    transform: rotate(-45deg);
    top: 37px;
    left: -43px;
    position: relative;
}
<div class="background">
    <div class="sold">Sold Out</div>
</div>
like image 119
Alex Char Avatar answered Sep 29 '22 19:09

Alex Char


Yes, and simple actually.

Demo http://jsfiddle.net/vakcgvtu/4/

.background {
    background-color:black;
    height:368px;
    position: relative;
    overflow: hidden;
}
.sold {
    background-color:red;
    font-size:26px;
    width:200px;
    text-align:center;
    height:40px;
    color:white;
    line-height:40px;
    position: absolute;
    left: -50px;
    top: 30px;
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
}
<div class="background">
    <div class="sold">Sold Out</div>
</div>
like image 34
Arbel Avatar answered Sep 29 '22 20:09

Arbel