我在另一个div中有一个div,我试图调整div,所以左侧触摸左侧,右侧触及顶部。有没有与CSS有关?
这是我的代码:
.background {
background-color:black;
height:368px;
}
.sold {
background-color:red;
font-size:26px;
width:200px;
text-align:center;
height:40px;
color:white;
line-height:40px;
}
<div class="background">
<div class="sold">Sold Out</div>
</div>
这是我的jfiddle:http://jsfiddle.net/vakcgvtu/
答案 0 :(得分:5)
您可以使用transform
:
.background {
background-color:black;
height:368px;
position: relative;
overflow: hidden;
}
.sold {
background-color:red;
font-size:26px;
width:200px;
text-align:center;
height:40px;
color:white;
line-height:40px;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
top: 37px;
left: -43px;
position: relative;
}
&#13;
<div class="background">
<div class="sold">Sold Out</div>
</div>
&#13;
答案 1 :(得分:2)
是的,实际上很简单。
演示 http://jsfiddle.net/vakcgvtu/4/
.background {
background-color:black;
height:368px;
position: relative;
overflow: hidden;
}
.sold {
background-color:red;
font-size:26px;
width:200px;
text-align:center;
height:40px;
color:white;
line-height:40px;
position: absolute;
left: -50px;
top: 30px;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
&#13;
<div class="background">
<div class="sold">Sold Out</div>
</div>
&#13;
答案 2 :(得分:1)
在这里,我改变了你transform rotate
和position relative
CSS。
答案 3 :(得分:1)
http://jsfiddle.net/vakcgvtu/2/
.sold {
background-color:red;
font-size:26px;
width:200px;
text-align:center;
height:40px;
color:white;
line-height:40px;
left: -50px;
top: 30px;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
position: relative;