Ich stoße hier auf eine Wand, hoffe, dass jemand helfen kann.css - container div shrink-to-fit Inhalt
Ich habe ein Container-Div mit einem schwarzen Hintergrund, den ich dynamisch den Inhalt "verkleinern" muss. Ich habe versucht Display: Inline-Block und mehrere andere Fixes dafür, aber ohne Erfolg.
Der Inhalt im Inneren ist eine große Anzahl von div-Boxen, die flush sind: links. Diese Anzahl von Feldern kann sich bei jedem Laden der Seite dynamisch ändern.
Hier ist meine CSS:
#blackboard {
background-color: black;
padding: 2px;
max-width: 580px;
display: inline-block;
}
.box {
height: 40px;
width: 34px;
border: 1px solid black;
margin: 1px;
float: left;
background-color: White;
display: inline-block;
}
Und mein HTML:
<div id="blackboard">
<div class="box" id="topbox1"></div><div class="box" id="topbox2"></div><div class="box" id="topbox3"></div><div class="box" id="topbox4"></div><div class="box" id="topbox5"></div><div class="box" id="topbox6"></div><div class="box" id="topbox7"></div><div class="box" id="topbox8"></div><div class="box" id="topbox9"></div><div class="box" id="topbox10"></div><div class="box" id="topbox11"></div><div class="box" id="topbox12"></div><div class="box" id="topbox13"></div><div class="box" id="topbox14"></div><div class="box" id="topbox15"></div><div class="box" id="topbox16"></div><div class="box" id="topbox17"></div><div class="box" id="topbox18"></div><div class="box" id="topbox19"></div><div class="box" id="topbox20"></div><div class="box" id="topbox21"></div><div class="box" id="topbox22"></div><div class="box" id="topbox23"></div><div class="box" id="topbox24"></div><div class="box" id="topbox25"></div><div class="box" id="topbox26"></div><div class="box" id="topbox27"></div><div class="box" id="topbox28"></div><div class="box" id="topbox29"></div><div class="box" id="topbox30"></div><div class="box" id="topbox31"></div><div class="box" id="topbox32"></div><div class="box" id="topbox33"></div><div class="box" id="topbox34"></div><div class="box" id="topbox35"></div>
<div style="clear:both;"></div>
</div>
einfacher ist es hier zu sehen, aber:
http://jsfiddle.net/pbspry/L8e34tvx/
Im Grunde nur die div-Container benötigen (schwarz) so zu wickeln, dass der gleiche Schwarzraum (nur wenige Pixel) vorhanden ist d das gesamte Raster, auch wenn die Fenstergröße geändert oder die Zoomeinstellungen des Browsers erhöht/verringert werden.
Danke für jede Hilfe!
UPDATE
Sieht aus wie das ist nicht wirklich ohne Javascript getan werden kann, was ich will nicht für eine Reihe von Gründen verwenden.
Die einfachste Lösung scheint zu sein, eine bestimmte Anzahl von Kästchen pro Zeile auszuwählen und dann nach dieser Zahl ein "clear: both" zu setzen. Dies erzwingt einen Zeilenumbruch und dann schrumpft das äußere div richtig, um zu passen (sogar bei verschiedenen Browser-Zoomstufen).
Gute Frage. Nicht relevant, aber etwas, das es wert wäre, wäre, das '# blackboard' div von' display: inline-block; 'zu' display: table; 'zu ändern. – www139