【问题标题】:Elements rendering in Chrome but not Firefox?在 Chrome 而不是 Firefox 中呈现元素?
【发布时间】:2012-05-15 04:33:14
【问题描述】:

解决了! 原来 body 标签没有 100% 的高度,而是两个宽度设置。 小学生错误,对不起。 这已经解决了。

我只使用网络元素和文本创建了一面美国国旗。

它在 Chrome 中以全彩色呈现良好,但在 Firefox 中仅显示星星和黑体背景。

有人可以强调这里出了什么问题吗?将 Doctype 放在页面上实际上会产生 Firefox 在页面的 Chrome 呈现方面遇到的相同问题。

Link to the flag

非常感谢任何帮助。

<html>
<head>
        <title>FLAG</title>
        <style>

        * {
        margin: 0;
        padding: 0;
        }

        body {
        position: relative;
        background: #000;
        font-family: Arial, Helvetica, sans-serif;
        font-size: small;
        color: #fff;
        margin: 0;
        width: 100%;
        width: 100%;
        }

        a {
        text-decoration: none;
        color: inherit
        }

        #star_wrapper {
        position: relative;
        }

        h1 {
        line-height:35%;
        font-size: 150px;
        padding: 5%;
        margin-top: 11%;
        margin-right: 5%;
        margin-left: 5%;
        z-index: -1;
        }

        #foot {
        position: absolute;
        background: #000; 
        top: 0px;
        width: 100%;
        height: 100%;
        }

        #stripes_wrapper {
        height: 100%;
        width: 100%;
        }       

        .box {
        position: relative;
        display: block;
        height: 7.692307692307692%;
        width: 100%;
        }

        .red {
        background: #B22234;
        }

        .white {
        background: #ffffff;        
        }

        #title_wrapper {
        background: #3C3B6E;
        height: 53.84615384615385%;
        width: 40%;
        z-index: 1;
        position: absolute;
        top: 0;
        }

        .liner {
        z-index: 2;
        }
        </style>
</head>

<body>
                <div id="foot">

            <div id="title_wrapper">
            <center>
                        <div id="star_wrapper">

            <h1>

            * * * * * *<br>
                * * * * *<br>
            * * * * * *<br>
                * * * * *<br>
            * * * * * *<br>
                * * * * *<br>
            * * * * * *<br>
                * * * * *<br>
            * * * * * *<br>

                </h1>
                            </div>

            </center>
            </div>



            <div id="stripes_wrapper">
            <div class="box red"></div>
            <div class="box white"></div>
            <div class="box red"></div>
            <div class="box white"></div>
            <div class="box red"></div>
            <div class="box white"></div>
            <div class="box red"></div>
            <div class="box white liner"></div>
            <div class="box red liner"></div>
            <div class="box white liner"></div>
            <div class="box red liner"></div>
            <div class="box white liner"></div> 
            <div class="box red liner"></div>           
            </div>
            </div>

            <center>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script src="jquery.fittext.js"></script>
        <script src="jquery-outline-1.0.js"></script>
        <script>
          $("h1").fitText(0.34);
        </script>
         <script type="text/javascript">
           $(document).ready(function(){    
            $("h1").outlineLetters({color: '#fff', size: 1});
           });
          </script>

</body>

【问题讨论】:

  • 请把代码带到这里(或到 jsfiddle)。否则,当问题得到解决时,指向您标志的链接将无助于理解问题
  • 我查看了您的 CSS,看起来您没有任何需要供应商标签的内容。您是否查看过您正在使用的 jQuery 插件,看看它们是否有浏览器限制?
  • 标志的高度是 0px,因此所有子元素的高度也都是 0px,因为它们都是基于 % 的。
  • 我不认为是插件,我在其他项目的浏览器上对它们进行了大量测试。该站点的主页eda.site50.net/index.html 使用非常相似的设置,但在FF 中呈现良好。 (顺便说一句大slogan,是我和朋友玩的网游)
  • 废话,我是个白痴,这是一个width: 100%; width: 100%;,在body标签中应该是width: 100%; height: 100%;

标签: jquery html css


【解决方案1】:

这不是问题,但是设置 DOCTYPE 是一个好习惯,没有它,浏览器会以怪癖模式呈现网页,设置字符集也是一个好习惯。

要解决您的问题,请尝试以下操作:(首先在您的条纹包装容器之后擦除杂散中心标签)

HTML:

<div id="stripes_wrapper">
        <div class="box red"></div>
        <div class="box white"></div>
        <div class="box red"></div>
        <div class="box white"></div>
        <div class="box red"></div>
        <div class="box white"></div>
        <div class="box red"></div>
        <div class="box white liner"></div>
        <div class="box red liner"></div>
        <div class="box white liner"></div>
        <div class="box red liner"></div>
        <div class="box white liner"></div> 
        <div class="box red liner"></div>           
        </div>
        </div>

<!-- ERASE THIS CENTER TAG -->
        <center>

CSS:

将此添加到您的 css 中:

html {
    height: 100%;
}

将 100% 高度添加到身体包装:

body {
    position: relative;
    background: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: small;
    color: #fff;
    margin: 0;  
    height: 100%;
} 

将高度 100% 添加到条纹包装器:

#stripes_wrapper {
    width: 100%;   
    height: 100%;
} 

这应该可以工作

【讨论】:

  • 我已经用缺少的高度 100% Derek 解决了这个问题,不过谢谢。投票为正确答案,因为它是。
【解决方案2】:
    <style>

    * {
    margin: 0;
    padding: 0;
    }

    body {
    position: relative;
    background-color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: small;
    color: #fff;
    margin: 0;
    }

    a {
    text-decoration: none;
    color: inherit
    }

            #star_wrapper {
            position: relative;
            }

    h1 {
    line-height:35%;
    font-size: 150px;
    padding: 5%;
    margin-top: 11%;
    margin-right: 5%;
    margin-left: 5%;
    z-index: -1;
    }

    #foot {
    position: absolute;
    background: #000; 
    top: 0px;
    width: 100%;
    height: 100%;
    }

    #stripes_wrapper {
    width: 100%;
    }       

    .box {
    position: relative;
    display: block;
    height: 7.692307692307692%;
    width: 100%;
    height:20px;
        background-color: #B22234;

    }

    .red {
    background-color: #B22234;
    }

    .white {
    background-color:  #ffffff;     
    }

    #title_wrapper {
    background-color: #3C3B6E;
    height: 53.84615384615385%;
    width: 40%;
    z-index: 1;
    position: absolute;
    top: 0;
    }

    .liner {
    z-index: 2;
    }
    </style>

【讨论】:

  • 这使颜色出现在 Firefox 中,但也使 Chrome 和 FF 中的所有内容变得一团糟。 〜感谢您的尝试:)
  • 当然弄得一团糟。那是因为你最初的 HTML/CSS 是完全错误的,现在是错误的但更少了。您没有设置元素的高度。我向你展示了哪里出了问题,现在你应该解决其余的问题。
  • 对不起,是的,你是对的。小学生错误,感谢您的回复。现在可以正常使用了。
  • 只是不要将你的这面旗帜展示给任何美国的忠实粉丝。这可能是另一个男生的错误。
  • 啊哈哈,是的,你说得有道理。我喜欢美国国旗,我只是想在 CSS 中做实验,看看是否可以制作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-03
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 2015-02-16
  • 2015-03-31
  • 2012-12-19
相关资源
最近更新 更多