我在父div中獲得了一些div。父分區只應該和其子分區一樣大。使父div與其子小一樣大
因此,這是當前視圖
function record(id, title, description, content, dateOfCreation) { // the object
this.id = id;
this.title = title;
this.description = description;
this.content = content;
this.dateOfCreation = dateOfCreation;
this.lastEdited = dateOfCreation;
}
function init(){
var elements = []; // all records get stored here
for (var i = 0; i < 3; i++) { // create some objects
elements.push(new record(
i,
"title " + i,
"description " + i,
"content " + i,
"date " + i));
}
$(elements).each(function (index, currentRecord) { // create the div containers
var recordContainer = $("<div></div>");
recordContainer.addClass("recordContainer");
$(document.body).append(recordContainer);
recordContainer.append($("<div>" + currentRecord.title + "</div>"));
recordContainer.append($("<div>" + currentRecord.description + "</div>"));
recordContainer.append($("<div>" + currentRecord.dateOfCreation + "</div>"));
recordContainer.append($("<div>" + currentRecord.lastEdited + "</div>"));
});
}
init(); // call the routine
.recordContainer{
margin: 10px;
border: solid; \t \t
border-width: 1px; \t \t
border-radius: 2px; \t \t
border-color: #e8e9e9;
box-shadow: 1px 1px 1px #999999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
所以我想有一個相對大小recordContainer
。在查找一些信息時,我嘗試將display: inline;
添加到「recordContainer」中。但是,然後這樣做,容器變得奇怪(?)。你需要嘗試一下,然後你會明白我的意思。
我怎樣才能達到我想要的div?
子容器應不大於它的父.. – ThisGuyHasTwoThumbs
你試過:'.recordContainer { 顯示:inline-block的; }' – UncaughtTypeError
哦,'display:inline-block;'就是這樣 – Question3r