Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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
Javascript 尝试对齐div';大小不同的,因此它们之间不会有任何空格 请不要把我的问题看成是重复的。我只是尝试不成功_Javascript_Html_Css_Jquery Masonry - Fatal编程技术网

Javascript 尝试对齐div';大小不同的,因此它们之间不会有任何空格 请不要把我的问题看成是重复的。我只是尝试不成功

Javascript 尝试对齐div';大小不同的,因此它们之间不会有任何空格 请不要把我的问题看成是重复的。我只是尝试不成功,javascript,html,css,jquery-masonry,Javascript,Html,Css,Jquery Masonry,正如在上面的帖子中所建议的,我使用了砌石。但没能成功。我正在使用codeigniter 以下是我正在使用的css #container { width:90%; margin:3% 0px 0px 10%; } .item { margin:10px 10px 10px 10px; float:left; width:240px; border:5px solid #f0f0f0; background-color:#d2dbde;

正如在上面的帖子中所建议的,我使用了砌石。但没能成功。我正在使用codeigniter

以下是我正在使用的css

#container {
    width:90%;
    margin:3% 0px 0px 10%;
}
.item {
    margin:10px 10px 10px 10px;
    float:left;
    width:240px;
    border:5px solid #f0f0f0;
    background-color:#d2dbde;
    border-radius:5px;
}
Javascript和js文件

<!-- include js files -->
<script type="text/javascript" src="http://www.myappdemo.com/KarmakExpo/js/jquery.min.js"></script>
<script type="text/javascript" src="http://www.myappdemo.com/KarmakExpo/js/jquery.masonry.min.js"></script>
<script type="text/javascript">
    $(function() {
        $('#container').masonry({
        // options
        itemSelector : '.item'
    });
});
</script>

$(函数(){
$(“#容器”)。砌体({
//选择权
itemSelector:“.item”
});
});
内容

<div id="container">
    <div class="item">
        <div id="usericon" style="width:240px;height:30px;">
        <!-- content -->
        </div>
        <div id="name">
        <!-- content -->
        </div>
    <div>
    <a href="<?php echo $link; ?>">
        <img src="<?php echo $picture = ($picture == null) ? '' : $picture; ?>" width="240px" height="auto">
    </a>
</div>

我在div部分显示图像、名称、日期等

动态div放置到位 (列数取决于文档窗口的宽度)

因为看起来您有规则宽度的div,所以您可以尝试以下方法:

注意:自从第一次回答这个简单的演示脚本以来,我已经对链接的JSFIDLE演示进行了实质性的修改。它现在几乎与此代码相似,但基本原理基本相同

有点像这样 JavaScript有点像这样 最终结果是动态创建宽度相等但高度不同的信息div,以列化方式进行布局。他们的自然倾向是尽可能地高出他们的父母,所以他们总是坐在他们上面的infodiv下面

由于列的显示属性设置为
inline
,因此它们往往并排放置在有空间的地方。需要注意的是,如果列的父列的宽度减小(在创建初始布局后),则最右边的列将被推到其他列的下方

至于PHP,这是另一个故事:-)

动态div取代了它们 (列数取决于文档窗口的宽度)

因为看起来您有规则宽度的div,所以您可以尝试以下方法:

注意:自从第一次回答这个简单的演示脚本以来,我已经对链接的JSFIDLE演示进行了实质性的修改。它现在几乎与此代码相似,但基本原理基本相同

有点像这样 JavaScript有点像这样 最终结果是动态创建宽度相等但高度不同的信息div,以列化方式进行布局。他们的自然倾向是尽可能地高出他们的父母,所以他们总是坐在他们上面的infodiv下面

由于列的显示属性设置为
inline
,因此它们往往并排放置在有空间的地方。需要注意的是,如果列的父列的宽度减小(在创建初始布局后),则最右边的列将被推到其他列的下方



至于PHP-这是另一个故事:-)

也许我遗漏了什么,但是。。。您只有一个带有
class=“item”
的div。您需要将
class=“item”
添加到要排列的所有元素中,而不仅仅是使用
class=“item”
将它们全部放在一个div中。是的,我只有一个div,它将在for循环中迭代……我尝试将class item添加到主div中的每个div中,但没有成功,反而丢失了样式。任何其他的suggestionOk,所以我遗漏了一些东西,但是for循环在您粘贴的代码中并不明显。确保它正在生成一个id为“container”的大div中包含一组class=“item”的div的有效html。。。除此之外,我不知道。查看页面的HTML源代码,检查您的PHP程序(或其他)是否真的生成了所需的HTML代码。也许我遗漏了一些东西,但是。。。您只有一个带有
class=“item”
的div。您需要将
class=“item”
添加到要排列的所有元素中,而不仅仅是使用
class=“item”
将它们全部放在一个div中。是的,我只有一个div,它将在for循环中迭代……我尝试将class item添加到主div中的每个div中,但没有成功,反而丢失了样式。任何其他的suggestionOk,所以我遗漏了一些东西,但是for循环在您粘贴的代码中并不明显。确保它正在生成一个id为“container”的大div中包含一组class=“item”的div的有效html。。。除此之外,我不知道。看看你网页的HTML源代码,看看你的PHP程序(或其他什么)是否真的生成了所需的HTML代码。你表现出的耐心给我留下了深刻的印象。虽然你提供的逻辑很专业,但我会努力的。。非常感谢你。顺便说一句,我是用砖石做的,但是IE不支持这个插件。@Ramarajudantuluri IE没有做很多有用的事情;-)如果你发现我的答案(基本上)解决了你的困境,我将非常感谢你接受我的答案。如果有什么不合适的地方,我可以调整一下。假设您从服务器上的数据库中提取数据,PHP中有一些函数可以创建DOM元素。它们可能会简化创建,然后将它们转储到列中。祝你好运:-)我没有使用DB。数据是从jsonAPI呈现的。此响应在控制器中解码,在那里按视图显示。@Ramarajudantuluri无论您如何收集填充,您似乎是在用PHP进行操作(或者可能不是?)。如果你是的话,看看这可能会有帮助。@Ramarajudantuluri我还更新了,更详细地展示了我认为你希望实现的目标。你表现出的耐心给我留下了深刻的印象。虽然你提供的逻辑很专业,但我会努力的。。非常感谢你。顺便说一句,我是用砖石做的,但是IE不支持这个插件。@Ramarajudantuluri IE没有做很多有用的事情;-)如果你发现我的答案(基本上)解决了你的困境,我将非常感谢你接受我的答案。如果有什么不合适的地方,我可以调整一下。假设你在拉
div.column {
    display:inline-block; /* "Columns" should be only as wide as their setting, */
    vertical-align:top;   /* should sit next to each other horizontally, */
    width:240px;          /* and be vertically aligned. */
    height:auto;
    margin:10px 0px 10px 10px;
}
div.column div.row {
    width:240px;          /* All "row" divs are of the same width, */
    height:auto;          /* but of varying heights */
    margin:0px 0px 10px 0px;
    padding:0px;
    background-color:#00f0f0;
}
(function () {
    var tdw = 240 + 0 + 10; // Div width + margin-left + margin-right
    window.addEventListener("load", function () {
        var ww = window.innerWidth, // how much width to play with?
            cn = Math.floor(ww / tdw), // how many columns will fit?
            cdl = [], // memory
            lc = 0, // alternation
            c = 0, // iteration
            ncd; // element object
        while (c++ < cn) {
            ncd = document.createElement("div"); // create columns
            ncd.setAttribute("class", "column"); // set their class
            document.body.appendChild(ncd); // add to page
            cdl.push(ncd); // remember them
        }
        c = 0;
        while (c++ < 100) { // this for demo // loop until there're no more
            ncd = document.createElement("div"); // create your divs
                // this could be where you add your div content
            ncd.setAttribute("class", "row"); // set their class
            lc = lc < cdl.length ? lc : 0; // alternate column as parent
            cdl[lc++].appendChild(ncd); // add the div to the column
            ncd.style.height = (200 * Math.random()) + "px"; // this for demo
                // or you could add the content via innerHTML
        }
    }, false);
}());​
How wide is the screen? Make (screen-width divided by column-width) columns. While we have new infodivs being created, add them to the columns. Don't add them all to one column, but shared them out equally.