How can I move the close button to the top-right corner of the box in slimbox (jQuery)
I want to have my button in the top-right corner, I tried position: absolute, but I think the position of the box is not relative so I can't use top: 0;.
Any suggestions?
CSS:
/* SLIMBOX */
#lbOverlay {
position: fixed;
z-index: 9999;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #000;
cursor: pointer;
}
#lbCenter, #lbBottomContainer {
position: absolute;
z-index: 9999;
overflow: hidden;
background-color: #fff;
}
.lbLoading {
background: #fff url(slimbox2/loading.gif) no-repeat center;
}
#lbImage {
position: absolute;
left: 0;
top: 0;
border: 10px solid #fff;
background-repeat: no-repeat;
}
#lbPrevLink, #lbNextLink {
display: block;
position: absolute;
top: 0;
width: 50%;
outline: none;
}
#lbPrevLink {
left: 0;
}
#lbPrevLink:hover {
background: transparent url(slimbox2/prevlabel.gif) no-repeat 0 15%;
}
#lbNextLink {
right: 0;
}
#lbNextLink:hover {
background: transparent url(slimbox2/nextlabel.gif) no-repeat 100% 15%;
}
#lbBottom {
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 10px;
color: #666;
line-height: 1.4em;
text-align: left;
border: 10px solid #fff;
border-top-style: none;
}
#lbCloseLink {
display: block;
float: right;
width: 31px;
height: 32px;
background: transparent url(slimbox2/clos开发者_JAVA技巧elabel.gif) no-repeat center;
margin: 5px 0;
outline: none;
}
#lbCloseLink:hover {
background: transparent url(slimbox2/closelabel_hover.gif) no-repeat center;
border-bottom: 0px;
}
#lbCaption, #lbNumber {
margin-right: 71px;
}
#lbCaption {
font-weight: bold;
}
The button #lbCloseLink
is inside of #lbBottomContainer
, which is positioned absolutely.
You can try margin-top: -Npx
on the button, but for this to work you have to know the height of your content and remove overflow: hidden
on #lbBottomContainer
.
The other solution might be to patch Slimbox and put the button into #lbCenter
.
I edited slimbox.js (first extend the script with : http://jsbeautifier.org/ ), and slimbox.css`
1) EDIT slimbox.js
I.setStyles({
width: N,
top: O, /* modified for TOP POSITION; original was O+t */
marginLeft: -N / 2,
visibility: "hidden",
display: ""
});
b.setStyles({
overflow:"visible", /* new line inserted for visibility TOP POSITION */
top: Math.max(0, z - (t / 2)),
width: N,
height: t,
marginLeft: -N / 2,
display: ""
});
2) EDIT slimbox.css
#lbBottom {
font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
font-size: 10px;
color: #666;
line-height: 1.4em;
text-align: left;
border-right: 10px solid #fff; /* modified: line inserted for TOP POSITION */
border-left: 10px solid #fff; /* modified: line inserted for TOP POSITION */
}
#lbCloseLink {
display: block;
float: right;
width: 66px;
height: 22px;
background: transparent url(closelabel.gif) no-repeat center;
margin:0 0 0 0; /* modified for TOP POSITION */
outline: none;
}
#lbCaption, #lbNumber {
margin-right: 71px;
margin-top:7px; /* line inserted for TOP POSITION */
}
According to version 2.05 you need to insert lbCloseLink into the lbCenter div; this can be approached by cutting the
w('<a id="lbCloseLink" href="#" />').click(C)[0],
and appending it to unnamed div with relative position
g=w('<div id="lbImage" rel=""/>').appendTo(a).append(p=w('<div style="position: relative;" />').append([w('<a id="lbCloseLink" href="#" />').click(C)[0],I=w('<a id="lbPrevLink" href="#" />').click(B)[0],d=w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0];c=w('<div id="lbBottom" />').appendTo(G).append([A=w('<div id="lbCaption" />')[0],K=w('<div id="lbNumber" />')[0],w('<div style="clear: both;" />')[0]])[0];
after that, you need to customize slimbox2.css, make the lbCloselink position absolute and z-index higher than 1 and also you may delete float: right; because since it has absolute position, float has no effect
#lbCloseLink {
position: absolute;
right:0px;
z-index: 2;
display: block;
width: %yourwidth%;
height: %yourheight%;
background: transparent url(closelabel.gif) no-repeat center;
outline: none;}
精彩评论