css形状里面有文字

时间:2015-07-28 07:13:15

标签: css shapes

我需要在下面的图片中创建这种形状,其中包含文本。 enter image description here

这是我尝试的方式:

HTML

1- 0x7fff9fc53e30
2- 2     // changed the value pointer points to
2- 0x7fff9fc53e30  // pointer stays the same
3- 0x7fff9fc53e38
4- 3

CSS

        <div class="header-bottom">

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

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

        </div>

我尝试添加transform:skew但是它会向右,向左和文本本身倾斜。

5 个答案:

答案 0 :(得分:11)

&#13;
&#13;
.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;
}
&#13;
<div class="shape">
  something something
</div>
<div class="shape">
  something else
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:5)

我喜欢使用:before伪类:

.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>

答案 2 :(得分:3)

请尝试以下代码

&#13;
&#13;
.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%;
}
&#13;
<div class="header-bottom">

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

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

</div>
&#13;
&#13;
&#13;

答案 3 :(得分:2)

for infos:

也可以使用背景渐变和背景大小:)

&#13;
&#13;
.shape{
  text-align:center;
  background:
    linear-gradient(65deg , transparent 50%,rgba(3,78,136,0.7) 50%) left no-repeat, 
    linear-gradient(0deg , rgba(3,78,136,0.7),rgba(3,78,136,0.7)) 30px 0 no-repeat;
  
  background-size:30px 100%, 100% 100%;
  width:200px;
  height:60px;
  line-height:60px;
  padding:0 20px;
  color:white;
  margin:20px auto;
  position:relative;
}
body {
  background:url(http://lorempixel.com/640/480);
  background-size:cover;
  }
&#13;
<div class="shape">
  sometext
</div>
<div class="shape">
  something else
</div><div class="shape">
  some more text 
</div>
<div class="shape">
  and so on  n on 
</div>
&#13;
&#13;
&#13;

答案 4 :(得分:0)

在您的情况下,您不能使用偏斜。相反,您应该在左侧添加一个旋转的三角形。

尝试添加:

.blue-rectangle:before {
    content: "";
    border-left: 78px solid transparent;
    border-top: 78px solid rgba(3,78,136, 0.7);
    position: absolute;
    top: 0;
    left: -78px;
    opacity: 0.7;
}

您可以自己完成剩余的调整。