div 与相邻 div 的高度不同

彼得哈斯曼

当我将 div 容器排成一排时,它们的高度不同。在更大的视野上使用我的小提琴时,您可以看到它。所以尝试整页或类似的东西。

我使用display:inline-block;是因为我希望它们排成一排。当窗口变小时,他们应该自己开始一个新行。

function record(title, description){ 
    // record object
    this.title = title;
    this.description = description;
}

function init(){
    var records = []; // array of all record objects
 
 	// fill the Data -> test routine
    var foo = "invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.At vero eos et accusam et justo duo dolores et earebum.Stet clita kasd gubergren, n"
    var bar = " labore et dolore magna aliquyam erat, sed diam voluptua.At vero eos et";
 	for (var i = 0; i < 7; i++) {
        records.push(new record("title " + i, i % 2 == 0 ? foo : bar));
    }
        
    // build up the view
    $(records).each(function (index, currentRecord) {
        var recordContainer = $("<div></div>"); // parent container
        recordContainer.addClass("recordContainer");
        $(document.body).append(recordContainer);

        var title = $("<div>" + currentRecord.title + "</div>"); // title div
        title.addClass("recordTitle");
        recordContainer.append(title);

        var description = $("<div>" + currentRecord.description + "</div>"); // text div
        description.addClass("recordDescription");
        recordContainer.append(description);
    });
}

init(); // run the code ...
body{background-color: #262626;}

.recordContainer{
    display: inline-block;
    width: 250px;
    height: 150px;
    margin: 20px;
    padding: 20px;
    background-color: #373737;
    color: #ffffff;
}

.recordContainer:hover{
    background-color: #484848;
}

.recordContainer:hover .recordTitle{
    color: #7dd7ef;
}

.recordTitle{
    margin-bottom: 10px;
    color: #5bb5cd;
}

.recordDescription{
    margin-bottom: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

贡巴

vertical-align: middle;在你的.recordContainer课堂使用

.recordContainer{
    display: inline-block;
    vertical-align: middle;
    width: 250px;
    height: 150px;
    margin: 20px;
    padding: 20px;
    background-color: #373737;
    color: #ffffff;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章