【问题标题】:Firefox absolute positioning failure火狐绝对定位失败
【发布时间】:2013-02-11 00:15:25
【问题描述】:

我的网站 http://cynthiawoodyardlandscapedesign.com/ 有几个问题只存在于 Firefox 中。

当点击主页上的图片时,两侧出现的箭头允许用户更改图片,位于页面顶部。包含箭头的 div 应该有 100% 的高度,我什至在 CSS 中添加了!important。只有 Firefox 不能正确显示。

我的 CSS (http://cynthiawoodyardlandscapedesign.com/css/main.css):

#sheet {
    width: 100%;
    height: 100%;
    position: fixed;
    overflow: hidden;
    top: 0;
    left: 0;
    background-color: rgba(0,0,0,0.8);
    display: table;
    z-index: 150;
}
#popover {
    margin: auto;
    background: rgba(0,0,0,0);
    text-align: center;
    padding: 10px;
    border: 1px solid black;
    position: relative;
    display: table-cell;
    vertical-align: middle;
}
#popover-image {
    height: 70%;
    border: 10px solid white;
}
#exit {
    position: absolute;
    top: 50px;
    color: white;
    font-size: 20px;
    font-weight: bold;
    width: 100%;
    text-align: center;
    z-index: 300;
    font-family: sans-serif;
}
#next-image, #previous-image { cursor: pointer; background:  transparent; }
#next-image::-moz-selection, #previous-image::-moz-selection,
#next-image::selection, #previous-image::selection { background: rgba(0,0,0,0); }
#leftArrow, #rightArrow {
    width: 20%;
    height: 100% !important;
    position: absolute;
    z-index: 200;
    display: table;
    background: transparent;
    top: 0;
}
#leftArrow { left: 0; } #rightArrow { right: 0; }
#next-image {
    display: table-cell !important;
    vertical-align: middle;
    margin: 0 auto;
    text-align: center;
    line-height: 50px;
    font-size: 50px;
    -webkit-text-stroke: 1px black;
    -moz-text-stroke: 1px black;
    height: 50px;
    width: 50px;
    color: white;
}
#previous-image {
    display: table-cell !important;
    vertical-align: middle;
    margin: 0 auto;
    text-align: center;
    line-height: 50px;
    font-size: 50px;
    -webkit-text-stroke: 1px black;
    -moz-text-stroke: 1px black;
    height: 50px;
    width: 50px;
    color: white;
}

我的 HTML (http://cynthiawoodyardlandscapedesign.com/default.php):

<div id="sheet">
    <div id="exit">Exit</div>

    <div id="popover">
        <div id="leftArrow"><div id="previous-image" onclick="previous()">&laquo;</div></div>

        <img src="watermark.php?src=images/main1.jpg&x=0&y=420&opactity=50" id="popover-image" onclick="close()" />

        <div id="rightArrow"><div id="next-image" onclick="next()">&raquo;</div></div>

    </div>

</div>

我尝试过的所有其他浏览器(IE 除外;我在 Mac 上)都能正确显示页面。

编辑:我遇到了更多 Firefox 问题。

http://cynthiawoodyardlandscapedesign.com/photography.php 处的页面显示了许多位于&lt;td&gt; 标记中的图片,在img 之后但在&lt;/td&gt; 之前有一个具有绝对位置的跨度,top: 10px; 在每个浏览器上(甚至 IE8 !!) 它不能正常工作。

我的 HTML 页面:

<table id="photos">
                <tr>
                    <td><img src="images/photo-thumbs/garden.jpg" /><span>Gardens</span></td><td><img src="images/photo-thumbs/trees.jpg" /><span>Trees</span></td><td><img src="images/photo-thumbs/shrubs.jpg" /><span>Shrubs</span></td><td><img src="images/photo-thumbs/perennials.jpg" /><span>Perennials</span></td>
                </tr>
                <tr>
                    <td><img src="images/photo-thumbs/annuals.jpg" /><span>Annuals</span></td><td><img src="images/photo-thumbs/tropicals.jpg" /><span>Tropicals</span></td><td><img src="images/photo-thumbs/bulb.jpg" /><span>Bulbs</span></td><td><img src="images/photo-thumbs/containers.jpg" /><span>Containers</span></td>
                </tr>
                <tr>
                    <td><img src="images/photo-thumbs/fruit.jpg" /><span>Fruit</span></td><td><img src="images/photo-thumbs/animals.jpg" /><span>Creatures</span></td><td><img src="images/photo-thumbs/people.jpg" /><span>People</span></td><td><img src="images/photo-thumbs/travel.jpg" /><span>Travel</span></td>
                </tr>
</table>
#photos td {
        width: 192px;
        height: auto;
        position: relative;
        border-right: 5px solid transparent;
    }
    #photos td img { width: 100%; border: 1px solid gold; }
    #photos td span {
        position: absolute;
        top: 10px;
        left: 0;
        width: 100%;
        text-align: center;
        background: rgba(0,0,0,0.4);
        padding-top: 2px;
        padding-bottom: 2px;
        color: #f0f0f0;
        font-weight: bold;
        font-family: "Source Sans Pro", sans-serif;
        display: none;
    }

【问题讨论】:

  • 几乎可以肯定这是由于您使用了display: table - 过去我遇到过很多问题,因为某些浏览器需要在display: table-cell 之外使用另一个带有display: table-row 的包装元素.为什么不使用position: absolute; top: 45%; right: 30px 或类似的东西而不是破解类似表格的布局?您也可以通过top: 50%; margin-top: -[arrowHeight/2]; 将箭头精确地放在中间。
  • 谢谢,这个答案效果很好。
  • @afterimagedesign 请看看我的回答,如果有任何问题或者我在哪里落后,请告诉我。

标签: html css firefox absolute


【解决方案1】:

这是您第二部分的答案:跨度位置的悬停问题。它工作正常,请参阅我在 html、css 和 jquery 代码中所做的以下更改。如果我遗漏了什么,请告诉我。

代码: http://jsfiddle.net/brNdq/1/

工作演示: http://jsfiddle.net/brNdq/1/embedded/result/

HTML:

<table id="photos">
      <tr>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/garden.jpg" /><span>Gardens</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/trees.jpg" /><span>Trees</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/shrubs.jpg" /><span>Shrubs</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/perennials.jpg" /><span>Perennials</span></div></td>
      </tr>
      <tr>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/annuals.jpg" /><span>Annuals</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/tropicals.jpg" /><span>Tropicals</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/bulb.jpg" /><span>Bulbs</span></div></td>
        <td><div class="img_container"><img src="http://cynthiawoodyardlandscapedesign.com/images/photo-thumbs/containers.jpg" /><span>Containers</span></div></td>
      </tr>
</table>

CSS:

.img_container {
    position:relative;
}

Jquery:从 TD 中移除悬停并将其放在类 .img_container 上

<script type="text/javascript">
$(document).ready(function () {
    $(".img_container").hover(function() {
        $(this).children('span').fadeIn('medium');
    }, function () {
        $(this).children('span').fadeOut('fast');
    });
});
</script>

【讨论】:

  • 非常抱歉!我在打电话,不小心给了错误答案 +50 声望。你的答案是完美的,我会给你双倍的!不过,我不知道如何给他们。如果可以的话,我愿意。再次,我很抱歉。
  • @afterimagedesign 您可以联系版主,了解他们可以进行更改。我的运气不好-:(
【解决方案2】:

身高的Usign百分比要见鬼了。由于某些历史原因,将 100% 高度作为窗口的高度,而不是显示区域。避免使用百分比 - 仅用于宽度:20% 的例外情况。

如果您想设置 height:100%,请使用 JavaScript。获取显示区域的高度并为这两个 div 设置它。我发布了一个示例,我将它用于覆盖窗口(在调整大小时也可以使用):

var updateInterval;

function showOverlay() {
  updateInterval = setInterval(function() {
    var h = 0;
    var s = 0;

    if (window.innerHeight) {
        h = window.innerHeight;
    }
    else if (document.documentElement.clientHeight) {
        h = document.documentElement.clientHeight;
    }

    if (document.body.scrollTop) {
        s = document.body.scrollTop;
    }
    else if (window.pageYOffset) {
        s = window.pageYOffset;
    }

    document.getElementById('overlay').style.height   = '' + h + 'px';
    document.getElementById('overlay').style.top = '' + s + 'px';
  }, 10);

  toogleHidden('overlay');
}

替换覆盖 id 为您的 ID,togleHidden 是我显示/隐藏元素的功能。

您可以使用类似的功能来正确放置元素 - 例如,您知道你的 elemtn 的高度是 32px,所以你会得到高度,除以 2 并减去 16:

var top = (h / 2) - 16;

您不需要将高度设置为 100%(除了整列应该是可点击的)。

希望这会有所帮助。

【讨论】:

    【解决方案3】:

    在 FF 中使用 style="display:block""position:absolute"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-01
      • 2012-01-14
      • 2018-11-21
      • 1970-01-01
      • 2011-01-04
      • 2011-08-02
      • 2013-10-30
      • 2011-08-04
      相关资源
      最近更新 更多