css形状里面有文字

uma*_*tha 9 css shapes

我需要在下面的图像中创建这种形状,其中包含文本. 在此输入图像描述

这是我尝试的方式:

HTML

        <div class="header-bottom">

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

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

        </div>
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

我尝试添加transform:skew但是它左右偏移和文本本身.

Pep*_*sta 11

.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;
}
Run Code Online (Sandbox Code Playgroud)
<div class="shape">
  something something
</div>
<div class="shape">
  something else
</div>
Run Code Online (Sandbox Code Playgroud)

  • 通知 (2认同)

Lin*_*TED 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
}
Run Code Online (Sandbox Code Playgroud)
<p class="blue-rectangle">sadasdasdasd</p>
Run Code Online (Sandbox Code Playgroud)

  • 我复制了他的CSS代码......它有大写的转换.在他的问题中没有任何要求小写..... (3认同)

G-C*_*Cyr 2

信息:

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

.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;
  }
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)