2 回答

TA贡献1828条经验 获得超6个赞
left:48%
left:50%
text-align:center
.
left:50%
.
transform
.triangle { position: absolute; left: 50%; transform: translate(-50%,0);}
transform
text-align:center
.
translate(-50%,0)
transform:translateX(-50%)
transform:translateY()
).
另外,下面是如何使用此方法对元素进行水平和垂直居中的方法: .triangle { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);}
注意:如果你用 right: 50%
或 bottom: 50%
,各自 translate
价值将是 50%
(不是否定) .
transform:rotate(45deg)
transform
.container::before { left: 50%; transform: translate(-50%,0) rotate(45deg);}
translate
rotate
translate
body {
background: #333333;
}
.container {
width: 98%;
height: 80px;
line-height: 80px;
position: relative;
top: 20px;
min-width: 250px;
margin-top: 50px;
}
.container-decor {
border: 4px solid #C2E1F5;
color: #fff;
font-family: times;
font-size: 1.1em;
background: #88B7D5;
text-align: justify;
}
.container::before {
top: -33px;
left: 50%;
transform: translate(-50%,0) rotate(45deg);
position: absolute;
border: solid #C2E1F5;
border-width: 4px 0 0 4px;
background: #88B7D5;
content: '';
width: 56px;
height: 56px;
}
<div class="container container-decor">great distance</div>
jsFiddle

TA贡献1780条经验 获得超1个赞
您可能会使用新的CSS 3。calc()函数,它允许您做算术来计算中心点。
要得到你的中心点,计算必须是:
50% - (56px / 2)
所以这最后是
50% - 28px
把这个放进calc()函数应该在浏览器中找到它,并将它完美地放置在中心。
body {
background: #333333;
}
.container {
width: 98%;
height: 80px;
line-height: 80px;
position: relative;
top: 20px;
min-width: 250px;
margin-top: 50px;
}
.container-decor {
border: 4px solid #C2E1F5;
color: #fff;
font-family: times;
font-size: 1.1em;
background: #88B7D5;
text-align: justify;
}
.container:before {
top: -33px;
left: calc(50% - 28px);
transform: rotate(45deg);
position: absolute;
border: solid #C2E1F5;
border-width: 4px 0 0 4px;
background: #88B7D5;
content: '';
width: 56px;
height: 56px;
}
<div class="container container-decor">great distance</div>
- 2 回答
- 0 关注
- 622 浏览
相关问题推荐
添加回答
举报