2013-03-14 45 views
1

我正在制作一个网站,并且我制作了一些按钮,并为它们添加了-webkit-box-flex属性。它运行良好。但是,当我向其中一个按钮添加下拉菜单时,-webkit-box-flex属性不再适用于它们,它不起作用。谁能告诉我发生了什么事?为什么-webkit-box-flex属性不起作用?

这里是一个的jsfiddle:

http://jsfiddle.net/hGT6E/

*{ 
margin: 0px; 
padding: 0px; 
} 

h1{ 
font: bold 20px PrimaSans BT; 
} 

h2{ 
font: italic 14px PrimaSans BT; 
    } 

header, section, footer, aside, nav, article, hgroup, ul, li{ 
display: block; 
} 

#wrapper{ 
max-width: 1000px; 
margin: 20px 0px; 
display: -webkit-box; 
display: -moz-box; 
-webkit-box-orient: vertical; 
-moz-box-orient: vertical; 

-webkit-box-flex: 1; 
-moz-box-flex: 1; 
margin-left: auto ; 
margin-right: auto ; 
} 

#searchbox{ 
float: right; 
margin-bottom: 10px; 
} 

body{ 
width: 100%; 
margin: 0; 
display:-moz-box; 
-moz-box-pack: center; 
display:-webkit-box; 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
background-image: -moz-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
background-repeat: no-repeat; 
background-attachment: fixed; 
    } 

#navigation{ 
display: block; 
padding: 10px; 
margin: 5px; 
margin-bottom: 0px; 
-webkit-border-radius: 15px; 
width: 800px; 
height: 60px; 
display: -webkit-box; 
-webkit-box-orient: horizontal; 
display: -moz-box; 
-moz-box-orient: horizontal; 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
background-image: -moz-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 

} 

#navigation li:hover ul{ 
display: block; 
} 

#navigation ul{ 
margin: 0px; 
padding: 0px; 
} 

#navigation li{ 
position: relative; 
float: left; 
list-style-type: none; 
} 

#navigation ul:after{ 
display: block; 
clear: both; 
visibility: hidden; 
} 

    #navigation li a{ 
text-decoration: none; 
display: block; 
color: black; 
border-right: 1px solid grey; 
padding: 10px 25px; 

} 

    #navigation ul ul{ 
position: absolute; 
border: 20px; 
left: 0px; 
width: 125px; 
display: none; 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
    } 

    #navigation ul ul li{ 
border: 1px solid grey; 
width: 99%; 
-webkit-transition: background 2s 
    } 

    #navigation ul ul li:hover{ 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#fffc01), color-stop(1, #ffde00)); 
    } 

#navigation ul ul li a{ 
border-right: none; 
    } 

    .navigation_button{ 
font: bold 18px PrimaSans BT; 
-webkit-box-flex: 1; 
width: 100px; 
padding: 10px; 
margin: 10px; 
text-align: center; 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
background-image: -moz-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#ffffff), color-stop(1, #bababa)); 
-webkit-border-radius: 10px; 
-webkit-transition: -webkit-transform 2s, opacity 2s, background 2s, scale 2s, 
    } 

    .navigation_button:hover{ 
-webkit-transform: scale(1.05); 
opacity: 1; 
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#fffc01), color-stop(1, #ffde00)); 
background-image: -moz-gradient(linear, left top, left bottom, color-stop(0, `enter code here`#fffc01), color-stop(1, #ffde00)); 
} 

#main_section{ 
border: 1px solid grey; 
width: 750px; 
margin-left: 40px; 
margin-right: 30px; 
border-top: 0px; 
height: 800px; 
margin-bottom: 10px; 
-webkit-border-bottom-right-radius: 10px; 
-webkit-border-bottom-left-radius: 10px; 
background-color: #f1f1f1; 
-webkit-box-flex: 1; 
} 

.article_1{ 
border: 1px solid gray; 
background: white; 
-webkit-box-flex: 1; 
margin-left: 10px; 
margin-right: 10px; 
margin-top: 10px; 
padding: 10px; 
    } 

    .article_1_footer{ 
text-align: right; 
    } 

    #footer{ 
text-align: center; 
font: italic 12px Times New Roman 
    } 

谢谢!

+0

您试图将'box-flex'属性应用于哪个元素?它不在小提琴中。你确实知道这些属性来自一个正在逐步淘汰的旧规范,对吗? https://gist.github.com/cimmanon/727c9d558b374d27c5b6 – cimmanon 2013-03-14 18:04:27

+0

我将它添加到.navigation_button – 2013-03-14 18:07:53

+0

我建议找到一种新策略,而不是使用Flexbox这个规格,因为它正在逐步淘汰。 – Michael 2013-03-14 18:31:53

回答

0

box-flex财产(现代名称:flex)只适用于项目是弹性项目。为了成为一个弹性项目,其父元素必须是一个柔性容器(具有box/flexbox/flex的显示值)。 .navigation_button元素的父亲是ul#nav_menu,其显示类型是块。

http://jsfiddle.net/hGT6E/1/

#nav_menu { 
    display: -webkit-box; 
    width: 100%; 
} 

我必须告诫不要依赖这些特性可用。它们来自2009年的Flexbox规格,并且可能在不久的将来会被放弃。如果您需要它们来支持旧的移动浏览器,请确保您还为每个媒体资源提供了现代版本。

+0

感谢您的修复和有用的信息。我会阅读新规范。 – 2013-03-14 19:01:50

-1

像前面解释的Cimmanon,

#parent { 
    /* the parent has to be setup */ 
    display: -webkit-box; 
    display: -moz-box; 
    display: -o-box; 
    display: box; 
} 

#child { 
    /* for the child to behave correctly */ 
    -webkit-flex-box: 1; 
    -moz-flex-box: 1; 
    -o-flex-box: 1; 
    flex-box: 1; 
} 

你在不支持的浏览器中查看它?

某些-vendor特定的前缀可能会丢失(相对于您的浏览器可访问性范围)。

这是一些新的学校使用flex的示例方式(生成自bennettfeely.com/flexplorer);

.flex-container { 
    display: -webkit-flex; 
    display: -moz-flex; 
    display: -ms-flex; 
    display: flex; 
    -webkit-flex-flow: row wrap; 
    -moz-flex-flow: row wrap; 
    -ms-flex-direction: row; 
    -ms-flex-wrap: wrap; 
    -ms-flex-flow: row wrap;  
    flex-flow: row wrap; 
} 

.flex-item { 
    -webkit-flex:1 auto; 
    -moz-flex:1 auto; 
    -ms-flex:1 auto; 
    flex:1 auto; 
} 

您可以通过用户Cimmanon提出看看Flex的浏览器支持上Caniuse

点,该前缀选择可能是不相关的你的问题,但不知何故,阅读你的CSS声明之后,我注意到你没有设置'basic'CSS3声明(显示:box; flex-box:1;)。所以我想了一会儿,这会解释你的情况,但事实并非如此。

+0

缺少前缀与问题无关。没有浏览器支持2009规范的前缀属性。 Opera从未支持2009规范,并且他们对当前规范的支持是免费的。 – cimmanon 2013-03-14 19:24:16

+0

@cimmanon:在http://css-tricks.com/using-flexbox/ ::上提到如果我们将旧的,新的和介于两者之间的语法组合在一起,我们可以获得体面的浏览器支持。可能是最常见的用例:订单控制的网格“。 Bur说得对,前缀与OP问题无关。 – 2013-03-14 19:33:13

+0

如果链接与问题或答案完全相关,那么该链接将会很有趣。我希望这篇文章不是您在Flexbox模块方面的专业知识的总和,因为它在内容上非常轻。 – cimmanon 2013-03-14 19:42:58

相关问题