Ich habe ein div in einem Elternteil div. Das Eltern-Div sollte nur so groß sein wie seine Child Divs.Machen Sie das Elternteil div so groß wie sein Kind
Das ist also die aktuelle Ansicht
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>
Also ich recordContainer
eine relative Größe wollen. Als ich nach Informationen suchte, habe ich versucht, display: inline;
zu "recordContainer" hinzuzufügen. Aber dann wird der Container seltsam (?). Sie müssen es ausprobieren, dann werden Sie sehen, was ich meine.
Wie kann ich mein gewünschtes div erreichen?
das Kind Behälter nicht größer sein sollte als es Eltern .. – ThisGuyHasTwoThumbs
Haben Sie versucht: '.recordContainer { display: inline-block; } ' – UncaughtTypeError
oh,' Anzeige: Inline-Block; 'das ist es – Question3r