2

I wanted to create a Rhombus shape around text in CSS. I've got the shape working however, the text in the shape is now always italic.

I've tried to set font-weight: normal but it isn't changing anything.

My current code is:

<span id="shape_background">
    Test text
</span>

#shape_background { 
    display: block;
    position: relative; 
    background-color: red; 
    -webkit-transform: skew(-20deg); 
    transform: skew(-20deg); 
}
web-tiki
  • 99,765
  • 32
  • 217
  • 249
thairish
  • 983
  • 2
  • 10
  • 16

2 Answers2

5

In order to prevent the text getting the skew effect:

  1. Wrap the text inside an element.
  2. Apply inverse skew to the child element i.e. skew(20deg), +ve value of 20deg to negate the effect of -20deg

#shape_background {
  display: block;
  position: relative;
  background-color: red;
  -webkit-transform: skew(-20deg);
  transform: skew(-20deg);
}
#shape_background .text {
  -webkit-transform: skew(20deg);
  transform: skew(20deg);
  padding-left: 5px;
}
<span id="shape_background">
  <p class="text">Test text</p>
</span>
m4n0
  • 29,823
  • 27
  • 76
  • 89
3

#shape_background {
  display: block;
  //position: relative;
  background-color: red;
  -webkit-transform: skew(-20deg);
  transform: skew(-20deg);
}
#shape_background span {
  display: inline-block;
  -webkit-transform: skew(20deg);
  transform: skew(20deg);
  color: white;
}
<span id="shape_background">
    <span>Test text</span>
</span>
Persijn
  • 14,624
  • 3
  • 43
  • 72