我想设置一个半宽像素的“左”dom样式
.div1{
position:absolute;
width:1000px;
left:calc(50% - 500px);
height:...;
}
.div2{
position:absolute;
width:2000px;
left:calc(50% - 1000px);
height:...;
}
因为我的代码,margin:0 auto
不适合我。
此外,JavaScript
也不是我的首选解决方案。我一直在用谷歌搜索几天。但对我来说没有想法。这是我预期的代码。
DIV{
position:absolute;
width:1000px;
left:calc(50% - -WIDTH-); // it's not right code
height:...;
}
有可能吗?
我不想用 javascript、scss 等来做。 非常感谢。
最佳答案
您必须使用TRANSFORM 属性
div {
position:absolute;
width:1000px;
left:50%;
transform:translate(-50%);
-webkit-transform:translate(-50%) !important; /* for webkit browsers*/
height:...;
}
关于css - 如何用半宽像素设置 'left',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54387654/