Hejsa!
I can't quite get this example to work.
http://aspitkbh.dk/lise/intro11/
The boxes are supposed to be the smallest possible width. (To not break the page while I wait for answer, I have set the width to auto there. Below is the code I thought would work.)
EDIT: I expect when the width is "too little", that the box will grow too high. Then I want to reduce the height until it is 170. The box will be too high or too wide because there's "too much" text in it.
<div class="myBoxExercise box1">Se en demo.
<button type="button" class="myButton" onclick="colorMe(this)">OK</button>
</div>
<div class="noMoreBox"></div>
<h3>Opgave 2</h3>
<div class="myBoxExercise box1">Du bliver.
<button type="button" class="myButton" onclick="colorMe(this)">OK</button>
</div>
.myBoxExercise {
height: 170px;
width: 100px;
padding: 5px;
float: left;
margin: 5px;
border-radius: 10px;
}
// JavaScript Document
// http://stackoverflow.com/questions/15227350/full-height-content-with-the-smallest-possible-width
$(document).ready(function() {
$( "div.myBoxExercise" ).each(function( index ) {
// The 160 = 170-2*5 is because you have to subtract the container padding and the element's own padding
// Or not?
while($(this).height() > 190) {
currentWidth = $(this).width();
$(this).width(currentWidth + 1);
}
console.log( index + ": " + $( this ).width() );
});
});