#speech
{
font-family: customfont;
font-size: 30px;
font-weight: bold;
color: #0B03FE;
position: relative;
width: 45%;
height: auto;
text-align: center;
background-color: #fff;
border: 8px solid #F50032;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;
-webkit-box-shadow: 2px 2px 4px #888;
-moz-box-shadow: 2px 2px 4px #888;
box-shadow: 2px 2px 4px #888;
}
#speech:before
{
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 30px;
top: 150px;
border: 25px solid;
border-color: #F50032 transparent transparent #F50032;
}
#speech:after
{
content: ' ';
position: absolute;
width: 0;
height: 0;
left: 38px;
top: 150px;
border: 15px solid;
border-color: #fff transparent transparent #fff;
}
What I have here is a speechbubble, made in CSS. This works perfectly when I have my speech div set with a fixed height, such as height: 150px;
, however I need the height to adjust itself depending on how much text the div contains. That's why I've got it like height: auto;
.
Now if you take a look at #speech:before
and #speech:after
, you can see that both have top set to top: 150px;
. This is the problem I'm having, as I need to alter both of these to whatever the height of #speech
is. I already have a way to get the dynamic height by the following Javascript:
window.onload = function(){
var element = document.getElementById('speech');
var speechheight = element.offsetHeight;
};
so now I have the height I need for both "tops" - I just can't seem to figure out a way to actually apply it. Could anyone help me?
Thanks in advance.