Dan*_*iel 8 css css-position microsoft-edge
我们正在尝试在图片的一角设置徽章。为此,我们使用父级<div>作为包装器和<span>内部。到目前为止,它对于Chrome,Firefox和IE11都可以正常工作,但是在MS Edge中,它无法按预期工作。似乎Edge计算出的right:特性与其他特性完全不同。
这是我的代码:
.parent {
width: 200px;
height: 200px;
border: 1px solid black;
position: relative;
overflow: hidden;
}
.child {
background-color: #e2001a;
position: absolute;
right: -65px;
width: 220px;
height: 50px;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
padding-left: 100px;
display: table;
z-index: 10;
color: white;
text-align: center;
line-height: 1.2;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<span class="child">Some cool text</span>
</div>Run Code Online (Sandbox Code Playgroud)
我做错什么了吗?或者Edge行为与其他浏览器有很大不同吗?
您可以按照下面的方式进行不同的操作,在 Edge 上似乎没问题*
.parent {
width: 200px;
height: 200px;
border: 1px solid black;
position: relative;
overflow: hidden;
}
.child {
background-color: #e2001a;
position: absolute;
top: 0;
left: -20px;
right: -20px;
height: 50px;
text-align: center;
transform: translateX(30%) rotate(45deg) translateY(70%);
z-index: 10;
color: white;
text-align: center;
line-height: 1.2;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<span class="child">Some cool text</span>
</div>Run Code Online (Sandbox Code Playgroud)
*我不知道为什么...
更新以使用原始代码片段:
transform需要像上面那样进行更改,并且translateX()需要translateY()进行一些调整才能工作。
以下是适用于 Chrome、Firefox、Edge 和 IE11 的代码:
.parent {
width: 200px;
height: 200px;
border: 1px solid black;
position: relative;
overflow: hidden;
}
.child {
background-color: #e2001a;
position: absolute;
right: -65px;
width: 220px;
height: 50px;
transform: translateX(10%) rotate(45deg) translateY(100%); //wokring with translateX and translateY instead of just rotate
display: table;
z-index: 10;
color: white;
text-align: center;
line-height: 1.2;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<span class="child">Some cool text</span>
</div>Run Code Online (Sandbox Code Playgroud)