JavaScript css div grow upwards dynamically

Basically, i'm building a game. In my game I wan't the players to be able to speak with each other. You have a figure, and when you speak, your text goes in a speak bubble div over your character.

My dilemma is, that when i type to much text in the bubble, the bubble expands over the character. So i want the bubble to grow upwards. I've been trying to think of a way to do this in both JS and CSS, but i'd had to give up and ask you guys.

Here's an example: http://jsfiddle.net/tDrNN/

HTML

<div class="wrapper">
    <div class="character1" style="position: absolute; top: 124px; left: 392px; width: 36px; height: 36px; background-color: blue;">
        <div class="bubble"><span>Hi my name is Mads</span></div>
    </div>


    <div class="character2" style="position: absolute; top: 124px; left: 192px; width: 36px; height: 36px; background-color: blue;">
        <div class="bubble"><span>Hi my name is MadsHi my name is MadsHi my name is MadsHi my name is MadsHi my name is MadsHi my name is Mads</span></div>
    </div>
</div>

CSS

.bubble {
  position: relative;
  background-color:#eee;
  margin: 0;
  padding:2px;
  min-width:100px;
  -moz-border-radius:10px;
  -webkit-border-radius:10px;
  -webkit-box-shadow: 0px 0 3px rgba(0,0,0,0.25);
  -moz-box-shadow: 0px 0 3px rgba(0,0,0,0.25);
  box-shadow: 0px 0 3px rgba(0,0,0,0.25); 
  top: -80px;
}
.bubble:after {
  position: absolute;
  display: block;
  content: "";  
  border-color: #eee transparent transparent transparent;
  border-style: solid;
  border-width: 10px;
  height:0;
  width:0;
  position:absolute;
  bottom:-19px;
  left:1em;
}
.bubble span {
    height: auto !important;
    color: #000 !important;
    font-family: verdana;
}
Answer:1

Here's an edited fiddle: http://jsfiddle.net/Z8fg3/

Notice two main differences: the class bubble is also absolutely positioned (like the character), and, instead of specifying a top, it has a bottom equal to the height of the character (plus some padding for the arrow and stuff).

(I moved one of the character both to fit the bubble and to show that it sticks to it regardless.)

Answer:2

I am new to bootstrap. I am making an sidebar accordion navigation using data-toggle="collapse" but it closes the navigation by default. what should i do to open navigation by default and it get close ...

I am new to bootstrap. I am making an sidebar accordion navigation using data-toggle="collapse" but it closes the navigation by default. what should i do to open navigation by default and it get close ...

I am wondering if it's possible to detect words input. I have 2 options: The word to be written in an input, and at Enter press to fire a certain command like animate or go to url. The word to be ...

I am wondering if it's possible to detect words input. I have 2 options: The word to be written in an input, and at Enter press to fire a certain command like animate or go to url. The word to be ...

I have a relatively simple regex problem - I need to match specific words in a string, if they are entire words or a prefix. With word boundaries, it would look something like this: \b(word1|word2|...

I have a relatively simple regex problem - I need to match specific words in a string, if they are entire words or a prefix. With word boundaries, it would look something like this: \b(word1|word2|...

  1. javascript regex simulator
  2. js regex simulator

Let me cut to the chase. It's on this site: http://www.smb.nu/wip/kampanj/ The white bar with the links is supposed to stick to the top when scrolled past, this effect is achieved with some simple ...

Let me cut to the chase. It's on this site: http://www.smb.nu/wip/kampanj/ The white bar with the links is supposed to stick to the top when scrolled past, this effect is achieved with some simple ...