旋转的div出现在其父div上

时间:2016-11-25 12:16:10

标签: css rotatetransform

我想在另一个div中旋转一个div,但是旋转的div在另一个div上方出现。我附上了一张图片来更好地理解它。 This is what I have

And this is what I want

这是我的代码:



.offer{
    display: block;
    color: #ffffff;
    text-align: center;
    padding: 5px 0;
    position: absolute;
    top: 23px;
    z-index: 100;
    left: -33px;
    width: 140px;
    box-shadow: 0 1px 10px #666;
    -ms-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    -o-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";
    background: -moz-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #1e5799), color-stop(1%, #e09013), color-stop(100%, #e5b300));
    background: -webkit-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -o-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -ms-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: linear-gradient(to bottom, #1e5799 0%, #e09013 1%, #e5b300 100%);
}
.content{
    margin:0 auto;
    top:50px;
    position: relative;
    width: 20%;
    height: 200px;
    background-color: lightgray;
}

<div class="content">
  <div class="offer">Offer</div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

只需将overflow:hidden添加到.content

即可

&#13;
&#13;
.offer{
    display: block;
    color: #ffffff;
    text-align: center;
    padding: 5px 0;
    position: absolute;
    top: 23px;
    z-index: 100;
    left: -33px;
    width: 140px;
    box-shadow: 0 1px 10px #666;
    -ms-transform: rotate(-45deg);
    -moz-transform: rotate(-45deg);
    -o-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";
    background: -moz-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #1e5799), color-stop(1%, #e09013), color-stop(100%, #e5b300));
    background: -webkit-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -o-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: -ms-linear-gradient(top, #1e5799 0%, #e09013 1%, #e5b300 100%);
    background: linear-gradient(to bottom, #1e5799 0%, #e09013 1%, #e5b300 100%);
}
.content{
    margin:0 auto;
    top:50px;
    position: relative;
    width: 20%;
    height: 200px;
    background-color: lightgray;
    overflow: hidden;
}
&#13;
<div class="content">
  <div class="offer">Offer</div>
</div>
&#13;
&#13;
&#13;