Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 为什么我的flex box元素;浮动;当我';您是否已将它们的元素设置为堆叠在彼此的顶部(块)?_Css_Layout_Media Queries_Flexbox - Fatal编程技术网

Css 为什么我的flex box元素;浮动;当我';您是否已将它们的元素设置为堆叠在彼此的顶部(块)?

Css 为什么我的flex box元素;浮动;当我';您是否已将它们的元素设置为堆叠在彼此的顶部(块)?,css,layout,media-queries,flexbox,Css,Layout,Media Queries,Flexbox,我有一组元素,当页面为特定宽度(320px)时,我希望切换显示顺序。它们确实改变了顺序,但我不明白为什么元素是“浮动的”,而不是堆叠的。(“浮动”在引号中,因为我知道它实际上不是浮动的,所以我想…) 我有以下HTML: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <s

我有一组元素,当页面为特定宽度(
320px
)时,我希望切换显示顺序。它们确实改变了顺序,但我不明白为什么元素是“浮动的”,而不是堆叠的。(“浮动”在引号中,因为我知道它实际上不是浮动的,所以我想…)

我有以下HTML:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        /* Elements */
        html, body, div, form, fieldset, legend, label{
            margin: 0;
            padding: 0; 
        }
        body{ margin:0; padding:0; line-height:1; font-family:Arial, Helvetica, sans-serif; }
        table{
            border-collapse: collapse;
            border-spacing: 0;
        }
        th, td{
            text-align: left;
            vertical-align: top;
        }
        ul, li{padding: 0; margin:0;}
        h1, h2, h3, h4, h5, h6, th, td, caption { font-weight:normal; margin: 0 0 16px; }
        img { border: 0; }
        p{ margin: 0 0 16px; }
        a{}

        /* Forms */
        fieldset{ border:none; }
        input:focus, select:focus, textarea:focus{ outline: 1px solid #ccc; }
        textarea{ overflow: auto; }

        /* Utility */
        .error{color: #f00; }
        .left{float: left; }
        .right{float: right; }
        .clear{clear: both; }
        .hide{display: none; }


        *{ -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
        nav{
            background: #f00;
        }
        nav:after {
            content: ".";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }
        nav ul li{
            list-style: none;
            margin: 0 auto;
            text-align: center;
            float: left;
        }



        @media screen and (max-width: 320px){
            nav{max-width: 100%;}
            nav ul {
                width: 100%;
                display: -webkit-box;
                display: -moz-box;
                display: -ms-flexbox;
                display: -webkit-flex;
                display: flex;
            }
            nav ul li{
                -webkit-box-flex: 1;
                -moz-box-flex: 1;
                -webkit-flex: 1;
                -ms-flex: 1;
                flex: 1;
                display: block;
                float: none;
            }
            nav .home{
                -webkit-box-ordinal-group: 1;  
                  -moz-box-ordinal-group: 1;     
                  -ms-flex-order: 1;     
                  -webkit-order: 1;  
                  order: 1;
            }
            nav .projects, nav .services{
                -webkit-box-ordinal-group: 2;  
                  -moz-box-ordinal-group: 2;     
                  -ms-flex-order: 2;     
                  -webkit-order: 2;  
                  order: 2;
            }
            nav .about, nav .contact{
                -webkit-box-ordinal-group: 3;  
                  -moz-box-ordinal-group: 3;     
                  -ms-flex-order: 3;     
                  -webkit-order: 3;  
                  order: 3;
            }
        }
    </style>
</head>
<body>
    <header>
        <nav>
            <ul>
                <li class="projects">Projects</li>
                <li class="services">Services</li>
                <li class="home">Home</li>
                <li class="about">About</li>
                <li class="contact">Contact</li>
            </ul>
        </nav>
    </header>

    <section>

    </section>

    <footer>

    </footer>
</body>
</html>

文件
/*元素*/
html、正文、div、表单、字段集、图例、标签{
保证金:0;
填充:0;
}
正文{margin:0;padding:0;行高:1;字体系列:Arial,Helvetica,sans serif;}
桌子{
边界塌陷:塌陷;
边界间距:0;
}
th,td{
文本对齐:左对齐;
垂直对齐:顶部;
}
ul,li{填充:0;边距:0;}
h1,h2,h3,h4,h5,h6,th,td,标题{字体重量:正常;边距:0 0 16px;}
img{边界:0;}
p{margin:016px;}
a{}
/*形式*/
字段集{border:none;}
输入:焦点,选择:焦点,文本区域:焦点{轮廓:1px实心#ccc;}
text区域{溢出:自动;}
/*效用*/
.错误{颜色:#f00;}
.left{float:left;}
.right{float:right;}
.clear{clear:两者;}
.hide{display:none;}
*{-moz框大小:边框框;-webkit框大小:边框框;框大小:边框框;}
导航{
背景:#f00;
}
导航:之后{
内容:“.”;
显示:块;
身高:0;
明确:两者皆有;
可见性:隐藏;
}
李国荣{
列表样式:无;
保证金:0自动;
文本对齐:居中;
浮动:左;
}
@媒体屏幕和屏幕(最大宽度:320px){
导航{最大宽度:100%;}
导航ul{
宽度:100%;
显示:-网络工具包盒;
显示器:-moz盒;
显示:-ms flexbox;
显示:-webkit flex;
显示器:flex;
}
李国荣{
-webkit-box-flex:1;
-moz-box-flex:1;
-webkit-flex:1;
-ms-flex:1;
弹性:1;
显示:块;
浮动:无;
}
导航主页{
-webkit盒序数组:1;
-moz盒序数组:1;
-ms弹性订单:1;
-网络工具包订单:1;
顺序:1;
}
导航项目,导航服务{
-webkit盒序数组:2;
-moz盒序数组:2;
-ms弹性订单:2份;
-网络工具包订单:2份;
顺序:2;
}
导航,关于,导航,联络{
-webkit盒序数组:3;
-moz盒序数组:3;
-ms弹性订单:3份;
-网络工具包订单:3份;
顺序:3;
}
}
  • 项目
  • 服务
  • 主页 关于
  • 联系人
还有一个测试


有谁能告诉我为什么flex box父级中的元素彼此相邻浮动,而不是堆叠?谢谢你的帮助

找到了答案。未将
弹性方向
属性分配给弹性盒容器

更新了。

也许您可以添加:

flex-direction: column;
在您的媒体查询中


看看这里:

谢谢@Marconi,但我已经找到了答案。见: