CSS3 flex属性不起作用?

时间:2013-03-31 19:18:15

标签: html5 css3 layout flexbox

我无法理解2009年推出的新Flex模型。

有三个市长语法更改,对吧? 我一直在阅读本教程,我认为这是最新的。 http://css-tricks.com/using-flexbox/

它在chrome中看起来很好但它似乎对firefox不起作用。 这个概念很简单,我有一个内容框,里面有三篇文章,一篇文章包含左边的图片,一篇主要内容(细节)居中,中间是灵活的,右边是一个概览窗格。

如果我理解正确的话,这个CSS文件应该水平排列,同时扩展细节框。 Netbeans告诉我'flex:1'是一个未知的属性。我做错了什么?

#content { /*Eigenlijke tekst/artikels*/
    /* Oude chome, Android, Opera, IOS & safari syntax */
    display: -webkit-box;
    -webkit-box-orient: horizontal;

    /* Oude firefox syntax */
    display: -moz-box;
    -moz-box-orient: horizontal;

    /* Microsoft moet weer speciaal doen (IE) */
    display: -ms-flexbox;
    -ms-flex-orient: horizontal;

    /* Nieuwe chome syntax */
    display: -webkit-flex;
    -webkit-flex-direction: row;

    /* Nieuwste syntax */
    display: flex;
}

article {
    border: 1px solid black;
}
article[id="picture"] {
    width: 150px;
    padding: 10px;
    margin-left: -20px;
}
#content > article[id="details"] {
    -webkit-box-flex: 1;
    -moz-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    margin-left: 10px;
    margin-right: 10px;
    padding: 10px;
}
article[id="overview"] {
    width: 225px;
    padding: 10px;
}

这是HTML语法:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
        <!--<![endif]-->
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <link rel="stylesheet" href="css/detailpages.css">
        <jsp:useBean id="al" scope="application" class="beans.actionlisteners" />
        <script src="js/vendor/modernizr-2.6.2.min.js"></script>
    </head>
    <body>
        <div id="page_wrapper">
            <jsp:include page="header.jsp" />
            <jsp:include page="navigation.jsp" />
            <div id="content_wrapper">
                <section id="content">
                    <article id="foto">
                        <img src="img/festivals/rock_werchter_2013.png"
                             alt="Rock Werchter 2013 - afbeelding" width="140px"
                             draggable="true" ondragstart="<% al.dragstart(); %>"
                             />
                        Foto:&nbsp;&nbsp;
                    </article>
                    <article id="details">
                        <header>
                            <h2>Header van details</h2>
                        </header>
                            <p>Gegevens van festival</p>
                        <footer>
                            <h3>footer van details</h3>
                        </footer>
                    </article>
                    <article id="overzicht">
                        <header>
                            <h2>Lijsten</h2>
                        </header>
                            <p>Festivallijst & toevoegen</p>
                        <footer>
                            <h3>borderfactory dinges</h3>
                        </footer>
                    </article>
                </section>
            </div>
            <hr style="width: auto; margin-left: 20px; margin-right: 20px;" />
            <jsp:include page="footer.jsp" />
        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

Firefox实现2009规范(display: box)非常错误。当一个元素成为 flex容器时,它应该像一个与周围元素相关的块元素。 Firefox实现更像是一个表元素,因为它缩小到子元素的大小。添加显式宽度通常可以解决问题:

#content {
  width: 100%;
}