【问题标题】:Image gets cutt off when positioning outside of a modal window定位在模态窗口之外时图像被截断
【发布时间】:2014-09-21 00:08:44
【问题描述】:

我有这个 html 文件:

<div style="
width:400px;
height:300px;
background-color:#009966;">
</div>

我将它作为带有颜色框的模态窗口打开,它具有以下 CSS:

#cboxOverlay, #cboxWrapper, #colorbox {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    overflow: hidden;
}
#cboxWrapper {
    max-width: none;
}
#cboxOverlay {
    position: fixed;
    width: 100%;
    height: 100%}
#cboxBottomLeft, #cboxMiddleLeft {
    clear: left;
}
#cboxContent {
    position: relative;
}
#cboxLoadedContent {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
#cboxTitle {
    margin: 0;
}
#cboxLoadingGraphic, #cboxLoadingOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%}
#cboxClose, #cboxNext, #cboxPrevious, #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;
}
#cboxContent, #cboxLoadedContent, #colorbox {
    box-sizing: content-box;
    -moz-box-sizing: content-box;
    -webkit-box-sizing: content-box;
}
#cboxOverlay {
    background: #000;
}
#colorbox {
    outline: 0;
}
#cboxContent {
    margin-top: 32px;
    overflow: visible;
}
.cboxIframe {
    background: #fff;
}
#cboxError {
    padding: 50px;
    border: 1px solid #ccc;
}
#cboxLoadedContent {
    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;
}
#cboxClose {
    border: 0;
    padding: 0;
    margin: 0;
    overflow: visible;
    text-indent: -9999px;
    width: 20px;
    height: 20px;
    position: absolute;
    top: -30px;
    left:390px;
    background: url(../images/controls.png) no-repeat;
}
#cboxClose:active, #cboxNext:active, #cboxPrevious:active, #cboxSlideshow:active {
    outline: 0;
}
#cboxPrevious {
    background-position: 0 0;
    right: 44px;
}
#cboxPrevious:hover {
    background-position: 0 -25px;
}
#cboxNext {
    background-position: -25px 0;
    right: 22px;
}
#cboxNext:hover {
    background-position: -25px -25px;
}
#cboxClose {
    background-position: -50px 0;
    right: 0;
}
#cboxClose:hover {
    background-position: -50px -25px;
}
.cboxSlideshow_off #cboxPrevious, .cboxSlideshow_on #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 0;
    right: 44px;
}
.cboxSlideshow_off #cboxSlideshow:hover {
    background-position: -75px -25px;
}

我尝试过使用“X”按钮的位置,我希望它位于 DIV 之外,例如通过修改 #cboxClose 将其设置为顶部 50 像素和右侧 50 像素,但该图像被剪切了关闭,如您在照片中所见。

这是什么原因造成的?

【问题讨论】:

  • 代码是否存在于某处?或者你能把它(包括js)放在jsfiddle.net上吗?
  • 不是真的,包括图片在内的来源太多了,看不出我如何有效地把它放在小提琴上。
  • @nicolekanderson 你可以看到here 一个不同的实例——AJAX

标签: html css position css-position colorbox


【解决方案1】:

容器#cboxWrapper 设置了overflow: hidden;(靠近包含的CSS 的顶部);如果您将 overflow: visible; 添加到该选择器,您移动的 X 按钮应该是可见的。

我不建议更改原始的overflow: hidden; 声明,因为它涉及其他选择器,而只需添加以下内容:

#cboxWrapper {
    overflow: visible;
}

【讨论】:

  • 谢谢!实际上,我必须同时更改 #cboxWrapper, #colorbox 才能使其工作,仅更改其中一个是行不通的。它会以任何方式损害模态窗口的性能吗?另外,是否可以使用 right 属性而不是左侧来定义 x 按钮的位置?我尝试了一个负的右值,但它只到达了模态窗口的边缘。不过可以与 left 一起使用。
猜你喜欢
  • 2011-06-14
  • 1970-01-01
  • 2011-09-04
  • 2017-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多