如何使用 CSS 覆盖三角形 div?

How do I write over a triangle-shaped div using CSS?

我目前正在尝试在我使用 CSS 创建的三角形 div 上写字。

这里:

.triangle-topright {
  width: 0;
  height: 0;
  border-top: 100px solid gray;
  border-left: 100px solid transparent;
}
<div class="triangle-topright">view</div>

如您所见,视图放错了位置,因为我希望它位于形状内部。我还希望它旋转,这样对眼睛很好。我知道文本旋转是这样的(示例):

-moz-transform: rotate(-90deg);

我可以使用 CSS 实现目标还是需要添加一些 JS?

非常感谢!

这里是an example of doing it with just CSS

HTML

<section class="page_block">
    <div class="row">
        <div class="col-md-1">
            <div id="header">
                <h1 class="verticaltext">
                    Vert Text
                </h1>
            </div>
        </div>
        <div class="col-md-11">
            <p>Column Somethin?</p>
        </div>
    </div>
</section>

CSS

.page_block {
    margin:0px;
    padding:10px;
}
#header { 
    position: relative; 
}
.verticaltext {
    transform: rotate(45deg);
    transform-origin: right, top;
    -ms-transform: rotate(45deg);
    -ms-transform-origin:right, top;
    -webkit-transform: rotate(45deg);
    -webkit-transform-origin:right, top;
    position: absolute; 
    color: #ed217c;
}

使用伪元素

演示 - 1

.triangle-topright {
  width: 100px;
  height: 100px;
  transform: rotateZ(45deg);
  margin: 20px;
  position: relative;
  z-index: 1;
  text-align: center;
  line-height: 64px;
}

.triangle-topright:before {
  content: '';
  z-index: -1;
  position: absolute;
  top:0;
  left: 0;
  width: 0;
  height: 0;
  transform: rotateZ(-45deg);
  border-right: 100px solid gray;
  border-bottom: 100px solid transparent;
}
<div class="triangle-topright">view</div>

演示 - 2

.triangle-topright {
  width: 100px;
  height: 100px;
  margin: 20px;
  position: relative;
  z-index: 1;
  text-align: center
}

.triangle-topright:before {
  content: '';
  z-index: -1;
  position: absolute;
  top:0;
  left: 0;
  width: 0;
  height: 0;
  border-top: 100px solid gray;
  border-left: 100px solid transparent;
}
<div class="triangle-topright">view</div>

演示 - 3

.triangle-topright {
  width: 100px;
  height: 100px;
  transform: rotateZ(90deg);
  margin: 20px;
  position: relative;
  z-index: 1;
  text-align: center
}

.triangle-topright:before {
  content: '';
  z-index: -1;
  position: absolute;
  top:0;
  left: 0;
  width: 0;
  height: 0;
  border-top: 100px solid gray;
  border-left: 100px solid transparent;
}
<div class="triangle-topright">view</div>

演示 - 4

.triangle-topright {
  width: 100px;
  height: 100px;
  transform: rotateZ(90deg);
  margin: 20px;
  position: relative;
  z-index: 1;
  text-align: center
}

.triangle-topright:before {
  content: '';
  z-index: -1;
  position: absolute;
  top:0;
  left: 0;
  width: 0;
  height: 0;
  border-top: 100px solid gray;
  border-right: 100px solid transparent;
}
<div class="triangle-topright">view</div>

上面的一些答案已经达到了同样的效果。这是我的 JSfiddle,你可以玩玩。

http://jsfiddle.net/tmtg1oc8/

.container {
    position: relative;
}

.triangle {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-top: 100px solid gray;
    border-left: 100px solid transparent;
    z-index: -1;
}

.content {
    padding: 40px;
}

还有 html

<div class="container">
    <div class="triangle"></div>
    <div class="content">hello</div>
</div>