在我的colorbox代码中,这是默认的CSS代码:
#colorbox, #cboxOverlay, #cboxWrapper{
position: absolute;
top: 0;
left: 0;
z-index: 9999;
overflow: hidden;
}在这种情况下,颜色框显示在页面的中心,但上下滚动时不会移动。但是,当我将代码更改为以下代码时:
#colorbox, #cboxOverlay, #cboxWrapper{
position: fixed;
top: 0;
left: 0;
z-index: 9999;
overflow: hidden;
}当上下滚动时,颜色框会移动,但不会显示在页面的中心。如何组合这些效果?
发布于 2014-09-16 23:58:26
使用如下命令设置颜色盒的宽度、高度和偏移量:
#colorbox, #cboxOverlay, #cboxWrapper{
position:fixed;
top:50%;
left:50%;
z-index:9999;
overflow:hidden;
width: 500px; //set the width
height: 500px; // set the height
margin-left: -250px; // negative offset to center the element
margin-top: -250px // negative offset to center the element
}在这里,您将top和left中的位置设置为50%,将width和height设置为500px,然后使用负边距将元素的宽度和高度偏移一半(因为位置从左上角开始
https://stackoverflow.com/questions/25873330
复制相似问题