2016-10-15 2 views
-1

ich Bootstrap hier 3.Wie kann ich Grenze um dynamische div erstellen?

verwendet, ist mein HTML-Code

<div class="border-box"> 
    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3"> 
     <div class="padding-top">Record</div> 
     <div>Record</div> 
     <div>Record</div> 
     <div>Record</div> 
     <div>Record</div> 
    </div> 
    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9"> 
     <div>record1</div> 
     <div>record2</div> 
     <div>record3</div> 
     <div>record4</div> 
     <div>record5</div> 
    </div> 
</div> 

css:

.border-box { 
    border-bottom: 1px solid #ddd; 
    border-top: 1px solid #ddd; 
    border-right: 1px solid #ddd; 
    border-left: 1px solid #ddd; 
    margin-left: 15px; 
    margin-right: 15px; 
    height: 150px; 
    margin-bottom: 15px; 
    margin-top: 30px; 
} 

Hier stelle ich fix Höhe der Box, aber wenn der Gehalt an record5 erhöht , es geht aus der Box. Ich möchte, dass es dynamisch funktioniert.

+0

Wenn Sie die Höhe der von '.border-box' erhält es nie dynamisch anpassen, um seine Kinder Inhalt zu passen .... es wird immer ein Überlauf des Inhalts sein ... nehmen Sie diese Höhenregel heraus und Sie werden bemerken, wie sich die Höhe dynamisch einstellt – repzero

+0

Ich habe Höhe als vorübergehende Lösung eingeschlossen. und wenn ich die höhe aus der css-klasse entferne, wird kein kasten erstellt, sondern es wird nur ein zeilenrand erstellt. –

+1

legen Sie keine Höheneigenschaften wie Höhe, Mindesthöhe und Maximalhöhe fest. Add overflow: auto zu .border-box – Sharmila

Antwort

0

html

<div class="border-box"> 
    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3"> 
     <div class="padding-top">Record</div> 
     <div>Record</div> 
     <div>Record</div> 
     <div>Record</div> 
     <div>Record</div> 
    </div> 
    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9"> 
     <div>record1</div> 
     <div>record2</div> 
     <div>record3</div> 
     <div>record4</div> 
     <div>record5</div> 
    </div> 
</div> 

css

.border-box{ 
    border-bottom: 1px solid #ddd; 
    border-top: 1px solid #ddd; 
    border-right: 1px solid #ddd; 
    border-left: 1px solid #ddd; 
    margin-left: 15px; 
    margin-right: 15px; 
    height: 150px; 
    margin-bottom: 15px; 
    margin-top: 30px; 
    //this will trigger the overflow 
    overflow-y: scroll; 

} 
+0

Ich habe deinen Standpunkt verstanden. aber ich möchte nicht scrollbares div setzen. –

+0

dann verwenden Sie Javascript, um die Höhe der Box zu erhalten und etwas Höhe zur Standardhöhe hinzuzufügen – HuntsMan

0

nur height zu min-height

BTW ändern, können Sie all dies mit viel weniger Zeilen schreiben:

.border-box { 
    border: 1px solid #ddd; 
    margin: 30px 15px 15px; 
    min-height: 150px; 
} 
1

Sehen Sie diese fiddle

HTML

<div class="border-box"> 
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3"> 
    <div class="padding-top">Record</div> 
    <div>Record</div> 
    <div>Record</div> 
    <div>Record</div> 
    <div>Record</div> 
</div> 
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-9"> 
    <div>record1</div> 
    <div>record2</div> 
    <div>record3</div> 
    <div>record4</div> 
    <div>record5</div> 
    <div>record1</div> 
    <div>record2</div> 
    <div>record3</div> 
    <div>record4</div> 
    <div>record5</div> 
    <div>record1</div> 
    <div>record2</div> 
    <div>record3</div> 
    <div>record4</div> 
    <div>record5</div> 
    <div>record1</div> 
    <div>record2</div> 
    <div>record3</div> 
    <div>record4</div> 
    <div>record5</div> 
</div> 
</div> 

CSS

.border-box { 
border: 1px solid #ddd; 
margin:30px 15px 15px 15px; 
min-height:150px; 
overflow: hidden; 
} 
+0

Danke. Es funktioniert. –

Verwandte Themen