chrome和firefox之间的Flexbox问题

时间:2014-02-03 18:57:27

标签: html5 css3 flexbox

我问过这里的第一个问题,如果我输入的信息过多或信息不足,请原谅我。我正在创建一个使用flexbox的导航栏。我几乎已经把它钉了,除了当我拿#container并尝试以margin为中心时:0 auto; Chrome使它看起来很完美,似乎没有任何事情发生在Firefox中。任何人都可以告诉我,如果我在编码时出错导致这种差异。

以下是照片网址= http://s74.photobucket.com/user/rdjromans116/media/Archive/Chrome_zps0015716f.jpg.html网址= http://s74.photobucket.com/user/rdjromans116/media/Archive/Firefox_zpsa50cf83f.jpg.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Relentless Pictures</title>
<!--[if lt IE 9]>
<script src="dist/html5shiv.js"></script>
<![endif]-->
<link href='http://fonts.googleapis.com/css?family=Chela+One|Belgrano|Revalia|Gloria+Hallelujah|Zeyada' rel='stylesheet' type='text/css'>
<link href="_css/normalize.css" rel="stylesheet" type="text/css">
<link href="_css/R3PHome.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="wrapper">
<h1>Relentless Pictures</h1>
    <header id="mainHeader">
        <hgroup>
        <h2>Mission Statement</h2>
        <p>Hard work always pays off</p>
        <pre>
        Rawle Juglal
        <a href="tel://405-740-9697" title="Rawle Juglal">405-740-9697</a>
        <a href="mailto:rawledjuglal@gmail.com">rawledjuglal@gmail.com</a></pre>
        </hgroup>
    </header><!-- End of HEADER "mainHeader"-->
    <nav id="container">
    <h1 class="hide">Main Navigation</h1>
    <div id="one">
     <a href="#" title="homepage">Home</a>
    </div>
    <div id="two">
      <a href="#" title="production">Video/Audio Productions</a>
    </div>
    <div id="three">
      <a href="#" title="webDesign">Website Development</a>
    </div>
    <div id="four">
     <a href="#" title="applications" >Computer Programming</a>
    </div>
  </nav>

这是CSS

#wrapper {
    width:100%;
    margin: 0 auto;
    background: #333;
}
#container {
    display:-webkit-box;
    display:-moz-box;
    /*display:flex; Seperate CSS sheet will be needed for IE*/
    display:box;
    box-orient:horizontal;
    width:80%;
    margin:0 auto;
    background-color:black;
}

#container div {
  background: rgba(15,15,15,1);
  text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  display: block;
  text-align: center;
  border-radius: 5px;  

/*Shadow*/
-webkit-box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);
-moz-box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);
box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);

/*Gradient*/
background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
background-image: linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));

    padding: 10px 0px 10px 0px;
    width: 75px;
    margin: 10px 15px 10px 15px;
}

#container div:hover{
     /*Shadow*/
 -webkit-box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.8);
  -moz-box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.8);
  box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.8);

  /*Gradient*/
  background-image: -webkit-linear-gradient(bottom, rgba(9, 142, 143, 1), rgba(0, 0, 0, 0.4));
  background-image: -moz-linear-gradient(bottom, rgba(9, 142, 143, 1), rgba(0, 0, 0, 0.4));
  background-image: -o-linear-gradient(bottom, rgba(9, 142, 143, 1), rgba(0, 0, 0, 0.4));
  background-image: -ms-linear-gradient(bottom, rgba(9, 142, 143, 1), rgba(0, 0, 0, 0.4));
  background-image: linear-gradient(bottom, rgba(9, 142, 143, 1), rgba(0, 0, 0, 0.4));
 }

#one {
    -moz-box-flex:0;
    -webkit-box-flex:0;
    -ms-flex:1;
    box-flex:0;
}

#two {
    -moz-box-flex:1.4;
    -webkit-box-flex:1.2;
    -ms-flex:1.2;
    box-flex:1.2;
}

#three {
    -moz-box-flex:1;
    -webkit-box-flex:0.90;
    -ms-flex:1;
    box-flex:0.90;
}

#four {
    -moz-box-flex:1.05;
    -webkit-box-flex:1.05;
    -ms-flex:1;
    box-flex:1.05;
}

1 个答案:

答案 0 :(得分:3)

您使用的Flexbox属性来自旧的2009草案,如果不提供标准属性,永远不会使用。除了有缺陷,破碎和不完整(特别是Mozilla实现)之外,它们最终会被放弃以支持标准属性。

http://codepen.io/cimmanon/pen/iCfEu

#wrapper {
  width: 100%;
  margin: 0 auto;
  background: #333;
}

#container {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -moz-box-pack: justify;
  -ms-flex-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  width: 80%;
  margin: 0 auto;
  background-color: black;
}

#container div {
  background: #0f0f0f;
  text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.3);
  -webkit-box-flex: 1;
  -moz-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
  overflow: hidden;
  text-align: center;
  border-radius: 5px;
  /*Shadow*/
  -webkit-box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);
  -moz-box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);
  box-shadow: 0px 6px 0px rgba(0, 0, 0, 0.8);
  /*Gradient*/
  background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
  background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
  background-image: -o-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
  background-image: -ms-linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
  background-image: linear-gradient(top, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2));
  padding: 10px 0px 10px 0px;
  width: 75px;
  margin: 10px 15px 10px 15px;
}

.hide {
  display: none;
}

请注意,我已使用justify-content取消了Flex项目的所有独特flex属性。还应该注意的是,使用表/表格单元格显示属性而不是Flexbox可以提高效率并获得更好的浏览器支持。

#container {
    display: table;
    width:80%;
    margin:0 auto;
    background-color:black;
}

#container div {
    background: rgba(15,15,15,1);
    text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: table-cell;
    text-align: center;
    border-radius: 5px;
}