Infobox

by Daniel300

HTML

<div id="cell">
    <div id="info-1" class="info visible">Dynamic content
        <br />A: 123
        <br />B: 456</div>
    <input type="button" value="Show/Hide" onclick="changeInfo(1)" />
</div>

CSS

body {
    font-family:"Arial", sans-serif;
    color: #575757;
    font-size: 16px;
    text-align:center;
}
#cell {
    height:100px;
    width:100px;
    border:1px solid black;
    position:relative;
}
.info {
    position:absolute;
    display:block;
    left:98px;
    background: #555555;
    color: #FFFFFF;
    text-shadow: .5px .5px 2px #EEEEEE;
    z-index:1;
    border:1px solid black;
    border-radius:5px 5px;
    overflow:hidden;
    white-space: nowrap;
}
.info.hidden {
    visibility:hidden;
    opacity:0;
    width:0px;
    max-height:10px;
    transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out, visibility 0s linear .5s;
    -moz-transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out, visibility 0s linear .5s;
    -webkit-transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out, visibility 0s linear .5s;
}
.info.visible {
    width:150px;
    max-height:100px;
    transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out;
    -moz-transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out;
    -webkit-transition: width .5s ease-in-out, max-height .5s ease-in-out, opacity .5s ease-in-out;
}

JavaScript

function infoVisible(info, show) {
    if (show) {
        document.getElementById("info-" + info).className = document.getElementById("info-" + info).className.replace(/(?:^|\s)hidden(?!\S)/g, ' visible');
    } else {
        document.getElementById("info-" + info).className = document.getElementById("info-" + info).className.replace(/(?:^|\s)visible(?!\S)/g, ' hidden');
    }
}

function changeInfo(info) {
    if ((' ' + document.getElementById('info-' + info).className + ' ').indexOf(' hidden ') > -1) {
        infoVisible(info, true);
    } else {
        infoVisible(info, false);
    }
}