Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
HTML/CSS网格布局_Html_Css_Grid - Fatal编程技术网

HTML/CSS网格布局

HTML/CSS网格布局,html,css,grid,Html,Css,Grid,如何更改网格布局,使第二行块正好位于其上方相应块的下方,而不是形成一个全新的行 HTML 我没有得到你想要的东西。当我将该代码放入测试文件时,我在浏览器中获得以下内容: 在我看来,最后两个区块正好位于同一列中其他区块的下方 问题可能在于,您将容器的宽度指定为屏幕的百分比,将块的宽度指定为绝对值 请发表评论,这样我的答案就更清楚了,这是我从你的问题中能得到的所有信息。你是说这样吗? CSS: HTML: 纯CSS无法实现这一点。你必须使用它。我的意思是,一旦最后一个盒子的右边没有空间,就会创

如何更改网格布局,使第二行块正好位于其上方相应块的下方,而不是形成一个全新的行

HTML


我没有得到你想要的东西。当我将该代码放入测试文件时,我在浏览器中获得以下内容:

在我看来,最后两个区块正好位于同一列中其他区块的下方

问题可能在于,您将容器的宽度指定为屏幕的百分比,将块的宽度指定为绝对值

请发表评论,这样我的答案就更清楚了,这是我从你的问题中能得到的所有信息。

你是说这样吗?

CSS:

HTML:



纯CSS无法实现这一点。你必须使用它。

我的意思是,一旦最后一个盒子的右边没有空间,就会创建一个新行,第一个盒子紧靠在第一个盒子下面(现在在上面),下一个紧靠在第二个盒子下面,等等。它可能是一个容器宽度的东西,但即使有固定的宽度,问题仍然存在,我现在理解你的问题了。我在没有位置和浮动的情况下编辑了小提琴,但它并没有真正的帮助。我想知道这是否仅仅是CSS的可能。如果我发现什么,我会告诉你的。我的小把戏:我猜css的“浮动”部分只是水平对齐,而不是垂直对齐,但也许有人可以证实这一点。我猜我需要使用一个插件,比如Mashine(),而仅仅使用常规css是不可能的。它可以做到这一点,但我之所以避免列,只是因为我必须手动将任何新块分配给相应的列。当添加新的DIV时,它不会自动将它们正确对齐。
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
#container {
    position: absolute;
    width: 60%;
    left: 50%;
    margin-left: -30%;
    border: 1px dotted #333;
    padding: 20px;
}
.box1 {
    position: relative;
    float: left;
    width: 100px;
    height: 150px;
    background: #666;
    margin: 0 15px 15px 0;
}
.box2 {
    position: relative;
    float: left;
    width: 100px;
    height: 200px;
    background: #666;
    margin: 0 15px 15px 0;
}
.box3 {
    position: relative;
    float: left;
    width: 100px;
    height: 100px;
    background: #666;
    margin: 0 15px 15px 0;
}
<div id="container">

    <div class="box1"></div>
    <div class="box3"></div>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box2"></div>
    <div class="box1"></div>
    <div class="box1"></div>
    <div class="box3"></div>
    <div class="box2"></div>

</div>
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
#container {
    position: absolute;
    width: 60%;
    left: 50%;
    margin-left: -30%;
    border: 1px dotted #333;
    padding: 20px;
}
.contleft
{
    float: left;
    margin-right: 15px;
    width: 30%;
    position: relative;
    height: 100%;
}
.contmiddle
{
    float: left;
    margin-right: 15px;
    width: 30%;
    position: relative;
    height: 100%;
}
.contright
{
    float: left;
    width: 30%;
    position: relative;
    height: 100%;
}
.box1 {
    position: relative;
    float: left;
    width: 100px;
    height: 150px;
    background: #666;
    margin: 0 15px 15px 0;
}
.box2 {
    position: relative;
    float: left;
    width: 100px;
    height: 200px;
    background: #666;
    margin: 0 15px 15px 0;
}
.box3 {
    position: relative;
    float: left;
    width: 100px;
    height: 100px;
    background: #666;
    margin: 0 15px 15px 0;
}
<div id="container">

    <div class="contleft">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
        <div class="box1"></div>
    </div>
    <div class="contmiddle">
        <div class="box2"></div>
        <div class="box1"></div>
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    <div class="contright">
        <div class="box3"></div>
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box1"></div>
    </div>
</div>