在Chrome中工作正常,但在IE和Firefox中不起作用。CSS/样式/HTML/PHP

3

我无法解决这个令人烦恼的问题。尝试了很多搜索和测试,但没有任何作用。

我想要所有东西看起来像谷歌浏览器的第一张图片。在I.E.中,背景不同,标题不在中心。在Firefox中,框设置不正确。我希望每行有2个盒子。

我不知道为什么会这样。

我不明白为什么I.E.还在网上提供下载.. 真是个糟糕的浏览器

有人能帮我吗?

Chrome:

enter image description here

Firefox:

enter image description here

I.E.

enter image description here

在这里您可以查看index.php

HTML/PHP

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
<title>-</title>

<style type="text/css">
/*<![CDATA[*/
#title{color:red; padding-bottom: 240px; padding-left: 25px;}
#desc{color:blue; padding-bottom: 135px; padding-left: 5px;}
/*]]>*/
</style>

<style type="text/css">
/*<![CDATA[*/
 div.c1 {width: 953px}
/*]]>*/
</style>
</head>

<body>
    <div class="header navpos c1" id="nav">
            <table summary="header" border="0">
                <tr>
                    <td>
                        <ul>
                            <li class="home"><a href="index.html"></a></li>
                        </ul>
                    </td>
                    <td>
                        <ul>
                            <li class="about"><a href="manage.html"></a></li>
                        </ul>
                    </td>
                    <td>
                        <ul>
                            <li class="contact"><a href="contact.html"></a></li>
                        </ul>
                    </td>
                    <td>
                        <ul>
                            <li class="twitter"><a href="index.html"><img src="includes/images/f_logo.png" alt="** PLEASE DESCRIBE THIS IMAGE **" /></a></li>
                        </ul>
                    </td>
                    <td>
                        <ul>
                            <li class="facebook"><a href="index.html"><img src="includes/images/t_logo.png" alt="link to Syndicate Plus Twitter" /></a></li>
                        </ul>
                    </td>
                </tr>
            </table>
    </div>
    <div class="box c1">
        <?php while($products = mysql_fetch_array($result)) {?>
        <table style="float: left;" width="473" align="left" background="includes/images/box.gif" width="473" height="285">
            <tr>
                <td width="35%" height="100%" id="title"><?php echo $products['products'];?></td>
                <td width="70%" height="100%" id="desc"><?php echo $products['description'];?></td>
            </tr>
        </table>
    <?php
    }       
    ?>
    </div>
    <div class="footer"></div>
</body>
</html>

这里是style.css,它是与CSS相关的文件。

* {
margin : 0;
padding : 0;
}
html {
background-image : url(images/web_bg.png);
}
body {
width : 953px;
margin : auto;
}
img {
border : 0;
}
A:link {
text-decoration : none;
color : #0087dc;
}
A:visited {
text-decoration : none;
color : #0087dc;
}
A:hover {
text-decoration : none;
color : #0087dc;
}
a:active, a:focus {
outline : 0;
}
a {
outline : none;
}
.header {
background-image : url(images/header_bg.png);
width : 953px;
margin : auto;
}
.footer {
background-image : url(images/bot_new.png);
min-height : 229px;
max-height : 229px;
position: relative;
}
#nav {
float : left;
}
#nav li {
float : left;
list-style-type : none;
}
#nav .home a {
margin-left : -20px;
margin-top : 25px;
display : block;
background-image : url(images/header_home.png);
background-repeat : no-repeat;
width : 400px;
height : 54px;
}
#nav .about a {
margin-left : 300px;
margin-top : 30px;
display : block;
background-image : url(images/header_about.png);
background-repeat : no-repeat;
width : 64px;
height : 13px;
}
#nav .contact a {
margin-left : 20px;
margin-top : 30px;
display : block;
background-image : url(images/header_contact.png);
background-repeat : no-repeat;
width : 64px;
height : 13px;
}
#nav .twitter a {
margin-left : 40px;
margin-top : 30px;
display : block;
background-image : url(images/t_logo.png);
background-repeat : no-repeat;
width : 26px;
height : 26px;
}
#nav .facebook a {
margin-left : 5px;
margin-top : 30px;
display : block;
background-image : url(images/f_logo.png);
background-repeat : no-repeat;
width : 26px;
height : 26px;
}
#nav .home a:hover {
margin-left : -20px;
margin-top : 25px;
background : url(images/header_home_light.png);
background-repeat : no-repeat;
width : 400px;
height : 54px;
}
#nav .about a:hover {
margin-left : 300px;
margin-top : 30px;
background : url(images/header_about_light.png);
background-repeat : no-repeat;
width : 64px;
height : 13px;
}
#nav .contact a:hover {
margin-left : 20px;
margin-top : 30px;
background : url(images/header_contact_light.png);
background-repeat : no-repeat;
width : 64px;
height : 13px;
}

有什么问题吗?你想要实现什么效果,但是又出了什么问题?仅仅通过截图很难判断。 - Kyle
根据屏幕截图,实际上看起来Chrome和IE正在工作,而Firefox则是个问题儿童。您能否更详细、准确地描述问题,并尽可能不带偏见? - Joel Etherton
好的,我希望所有的东西看起来都像第一张图片Google Chrome。在IE中,背景不同,标题不在中心。在Firefox中,框没有正确设置。我想要每行有2个框。 - MOTIVECODEX
3个回答

1
将标题、内容和页脚包装在一个固定宽度的
中,以强制下一行在某个点换行。
<body>
<div id="wrapper">
  <div id="header">header</div>
  <div id="content">
      <script type="text/javascript">
        for (i=0;i<5;i++) { // example in javascript
          document.write("<div style='float:left;width:80px;height:80px;background-color:blue;margin:2px;'></div>");
        }
      </script>
  </div>     
  <div id="footer">footer</div>    
</div>
</body>

CSS:

body {
   text-align:center;
}
#wrapper {
    background-color:#eee;
    width:300px;
    margin: 0 auto;
    text-align:left;
}
#header {
    background-color:red;
}
#content {
}
#footer {
    clear:both;
    background-color:green;
}

工作代码和结果:http://jsfiddle.net/fsHd5/3/


在IE上工作,但所有内容都向左对齐。 在Firefox中没有发生任何事情。还有什么提示吗? - MOTIVECODEX
<div style="width:953px; margin: auto 0;">这样对吗?完全没有效果..这就是奇怪的地方,我以前试过这个没有用。就像代码讨厌我一样。 - MOTIVECODEX
在IE中,现在它位于中心。但为什么每次刷新背景图像都会改变样式呢?随机的,有时它显示背景图像,下一次它不显示,下一次它显示其中的一部分。在IE中按F5后。在Firefox中仍然没有效果。 - MOTIVECODEX
@F4LLCON 像 Toast 所写的那样,删除您之前设置的所有边距和宽度。您唯一需要的宽度是外部 DIV 的宽度,并向该 DIV 添加 background-image。 - yosh
好的,无论如何感谢您。我将以正确的方式重新编写代码,并查看现在拥有这些信息的结果。 - MOTIVECODEX
显示剩余4条评论

1
对于你的IE问题,你告诉#nav左浮动。实际上并没有真正需要这样做。我猜你打算将其应用于子元素。IE确实存在一个背景只扩展到内容高度的问题。除了通过显式设置高度来解决的有点“tricky”之外,我没有其他解决方案。
在Firefox中,它没有强制设置body的宽度,所以使用一个div来强制设置你想要的宽度。

当我更改 #nav 的浮动时,什么也没有发生。我用 div 包围它来强制执行,yosh 告诉我这样做,但是... 它不能正常工作。 - MOTIVECODEX
在尝试这些操作时,也要删除body的宽度。 - Toast
好的,无论如何感谢你。我将以正确的方式重写代码,并查看手头的这些信息所带来的结果。 - MOTIVECODEX
1
好的建议。再多一点建议:使用CSS来设置宽度,而不是使用width属性。高度也是如此。一般来说,如果可以用CSS实现,就用CSS。另外,您目前正在使用70%和35%作为td宽度。这些加起来超过了100%。 - Toast
谢谢,我没有注意到它是105%。我现在会制作一个干净的版本,希望它能成功。 - MOTIVECODEX

0
尝试使用"display: inline-block;"代码。
不确定,因为未经测试。

你是指style.css文件对吧?我把所有的display: block;都改成了display: inline-block;。但是没有任何区别。 - MOTIVECODEX

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接