【发布时间】:2017-12-28 19:08:04
【问题描述】:
我想创建一个带有 css 跨度和绝对位置的“X”,但跨度即使应该居中也不居中。
容器具有1px 的font-size。以及100em 的height 和width。因此我可以使用1em 作为父母大小的 1%。
我在跨度上使用了transform-origin: 0px 5em;,在不改变起点的情况下旋转它。元素以 20% top 和 left (20em) 开始,以 80% 结束(顶部和左侧)。
为了得到所需的width,我简单地计算了:Square root( square of (60) * 2)(勾股定理)(60,因为开始和结束 20 -- 100-20*2)
但由于某种原因,X 显然没有居中。你知道我做错了什么吗?
body
{
margin: 0px;
}
.check
{
font-size: 1px;
position: relative;
height: 100em;
width: 100em;
background-color: white;
border-radius: 50%;
transition: .3s;
box-shadow: 0px 0px 10px red inset;
}
.check span
{
position: absolute;
display: block;
height: 10em;
width: 0px;
background-color: #00FF00;
transition:.3s;
}
.check.red span
{
background-color: #FF0000;
transform-origin: 0px 5em;
transform: rotate(45deg);
top: 20em;
left: 20em;
}
.check.red span:nth-of-type(2)
{
transform: rotate(135deg);
top: 20em;
left: 80em;
}
.check.red:hover span
{
width: 84.852813742em;
}
<body>
<div class="check red">
<span></span>
<span></span>
</div>
</body>
【问题讨论】:
-
它在这里,但你也使用了变换原点。一旦旋转以补偿,边缘就会下降:)
标签: css