Closed. This question is off-topic. It is not currently accepting answers. Learn more
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
5年前关闭。
我正在尝试在我的站点的特定are上放置DIV,使用以下代码:
<div style="position: fixed; left: 780px; right: 0; width:285px; z-index:9999; display:block; top:60px; color: #000; background-color:#fff; -webkit-border-radius:2px; -moz-border-radius:2px; border-radius:2px; box-shadow:0px 2px 5px #303030;">TEXT</div>

它在我的屏幕上运行良好,因为我的屏幕分辨率是1240px宽(记住的一点是DIV im试图设置的):
但是,如果我在另一台屏幕分辨率不同的电脑上看到这个网站,它会改变显示的位置,因为它从左边设置了780px。
有没有办法从中间而不是左(或右)边距设置它?
我能做什么?

最佳答案

有一种简单的方法可以从中间定位:
CSS:

#your-container {
 position: fixed or absolute
 left: 50%
 width: must have a fixed width (eg 250px)
 margin-left: -(width / 2) plus or minus offset (eg: -(250px / 2) for centered position or -(250px / 2) + 100px for position 100px to the right from the center)
}

这只是回答你的问题,但我也倾向于@Hashem Qolami在他的评论中给出的建议!
PPShave a look this CODEPEN | maybe this strategy will work your scenario...
希望有帮助:)

10-05 20:29
查看更多