如何在彩色框中重新定位展开的图像

时间:2013-12-15 22:27:26

标签: jquery css colorbox

我是彩盒新手! 我四处寻找一个好的灯箱 - 并最终选择了彩盒。

但问题是我需要将背景(我认为它是#cboxOverlay)放在左边120px。即所以原始页面仍然显示在下面。

#cboxOverlay{background:#abc;    left:120px; )

似乎工作,

但是如何重新定位扩展图像以使它们位于(背景的新大小)的中心。目前它位于屏幕的中心。 我已经尝试了很多css更改,但没有一个有意义的解决方案。

#colorbox{ ... margin:auto !important;}

似乎不起作用。

有人有任何建议吗。

韩国社交协会

2 个答案:

答案 0 :(得分:0)

要使用margin: 0 auto;技巧居中对象,您需要3个关键属性:

margin: 0 auto;
display: block / table / box;
width: [anythingOtherThanAuto];

Example Fiddle

其他选项包括:

transform: translateX(50%);

或我个人的最爱(这对你帮助不大,但很高兴知道):

position: relative / absolute / fixed;
right: 15%;
left: 15%;
top: 15%;
bottom: 15%;

这更像是......“我需要完美地适应叠加背景”......有点儿。

答案 1 :(得分:0)

在这里添加css(不知道在哪里放了这么长的代码。 抱歉,我无法看到将此应用于colorBox的位置。 下面是他们的colorbox.css我突出显示了我将Overlay左移120px的位置。但是哪个/如何重新集中#colorbox。

'code'
/*
    Colorbox Core Style:
    The following CSS is consistent between example themes and should not be altered.
*/
#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
#cboxWrapper {max-width:none;}
#cboxOverlay{position:fixed; width:100%; height:100%;}
#cboxMiddleLeft, #cboxBottomLeft{clear:left;}
#cboxContent{position:relative;}
#cboxLoadedContent{overflow:auto; -webkit-overflow-scrolling: touch;}
#cboxTitle{margin:0;}
#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
.cboxPhoto{float:left; margin:auto; border:0; display:block; max-width:none; -ms-interpolation-mode:bicubic;}
.cboxIframe{width:100%; height:100%; display:block; border:0;}
#colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box; -moz-box-sizing:content-box; -webkit-box-sizing:content-box;}

/* 
    User Style:
    Change the following styles to modify the appearance of Colorbox.  They are
    ordered & tabbed in a way that represents the nesting of the generated HTML.
*/
#cboxOverlay{background:#fff;     left:120px; <!-- CHANGED --> }
#colorbox{outline:0;}
    #cboxContent{margin-top:32px; overflow:visible; background:#000;}
        .cboxIframe{background:#fff;}
        #cboxError{padding:50px; border:1px solid #ccc;}
        #cboxLoadedContent{background:#000; padding:1px;}
        #cboxLoadingGraphic{background:url(images/loading.gif) no-repeat center center;}
        #cboxLoadingOverlay{background:#000;}
        #cboxTitle{position:absolute; top:-22px; left:0; color:#000;}
        #cboxCurrent{position:absolute; top:-22px; right:205px; text-indent:-9999px;}

        /* these elements are buttons, and may need to have additional styles reset to avoid unwanted base styles */
        #cboxPrevious, #cboxNext, #cboxSlideshow, #cboxClose {border:0; padding:0; margin:0; overflow:visible; text-indent:-9999px; width:20px; height:20px; position:absolute; top:-20px; background:url(images/controls.png) no-repeat 0 0;}

        /* avoid outlines on :active (mouseclick), but preserve outlines on :focus (tabbed navigating) */
        #cboxPrevious:active, #cboxNext:active, #cboxSlideshow:active, #cboxClose:active {outline:0;}

        #cboxPrevious{background-position:0px 0px; right:44px;}
        #cboxPrevious:hover{background-position:0px -25px;}
        #cboxNext{background-position:-25px 0px; right:22px;}
        #cboxNext:hover{background-position:-25px -25px;}
        #cboxClose{background-position:-50px 0px; right:0;}
        #cboxClose:hover{background-position:-50px -25px;}
        .cboxSlideshow_on #cboxPrevious, .cboxSlideshow_off #cboxPrevious{right:66px;}
        .cboxSlideshow_on #cboxSlideshow{background-position:-75px -25px; right:44px;}
        .cboxSlideshow_on #cboxSlideshow:hover{background-position:-100px -25px;}
        .cboxSlideshow_off #cboxSlideshow{background-position:-100px 0px; right:44px;}
        .cboxSlideshow_off #cboxSlideshow:hover{background-position:-75px -25px;}


'code'