Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css shapes with text inside it

Tags:

css

shapes

I need to create this kinda shape in the image below which contains text in it. enter image description here

This is how I tried :

HTML

        <div class="header-bottom">

            <div class="blue-rectangle">
                <p>sadasdasdasd</p>
            </div>

            <div class="blue-rectangle">
                <p>dsasdasdasda</p>
            </div>

        </div>

CSS

.header-bottom{
position: absolute;
right:13%;
bottom:5%;
}

.blue-rectangle {
background-color: rgba(3,78,136,0.7);
padding: 10px 20px 10px 200px;
margin-bottom: 20px;
}

.blue-rectangle p{
color:white;
text-transform: uppercase;
font-size:18px;
}

i tried adding transform:skew but it skews both right, left and the text itself.

like image 626
umanga shrestha Avatar asked Jul 28 '15 07:07

umanga shrestha


3 Answers

.shape{
  text-align:center;
  background-color:rgba(3,78,136,0.7);
  width:200px;
  height:60px;
  line-height:60px;
  color:white;
  margin:20px auto;
  position:relative;
}
.shape:before{
  content:"";
  width:0px;
  height:0px;
  border-top:60px solid rgba(3,78,136,0.7);
  border-left:60px solid transparent;
  position:absolute;
  right:100%;
  top:0px;
}
<div class="shape">
  something something
</div>
<div class="shape">
  something else
</div>
like image 112
Pepo_rasta Avatar answered Oct 18 '22 17:10

Pepo_rasta


I like to use a :before pseudo class for this:

.blue-rectangle {
  color:white;
  text-transform: uppercase;
  font-size:18px;
  padding: 10px 20px 10px 200px;
  background-color: rgba(3,78,136,0.7);
  width: 200px;
  position: relative;
  margin-left: 50px;
}
.blue-rectangle:before {
  content: "";
  position: absolute;
  border: 21px solid transparent;
  border-top-color: rgba(3,78,136,0.7);
  border-right-color: rgba(3,78,136,0.7);
  right: 100%;
  top: 0;
  width: 0;
  height: 0
}
<p class="blue-rectangle">sadasdasdasd</p>
like image 20
LinkinTED Avatar answered Oct 18 '22 17:10

LinkinTED


Please try following code

.header-bottom {
  position: absolute;
  right: 13%;
  bottom: 5%;
}
.blue-rectangle {
  height: 60px;
  background-color: rgba(3, 78, 136, 0.7);
  padding: 10px 20px 10px 200px;
  margin-bottom: 20px;
  position: relative;
}
.blue-rectangle p {
  color: white;
  text-transform: uppercase;
  font-size: 18px;
  position: relative;
}
.blue-rectangle:before {
  content: '';
  width: 0;
  height: 0;
  border-top: 80px solid rgba(3, 78, 136, 0.7);
  border-left: 80px solid transparent;
  position: absolute;
  top: 0;
  right: 100%;
}
<div class="header-bottom">

  <div class="blue-rectangle">
    <p>sadasdasdasd</p>
  </div>

  <div class="blue-rectangle">
    <p>dsasdasdasda</p>
  </div>

</div>
like image 23
w3debugger Avatar answered Oct 18 '22 19:10

w3debugger