L'unica idea che m'è venuta per adattare un box in base al suo contenuto è utilizzare la proprietà offsetWidth (read-only) del contenuto racchiuso in tag in-line (tipo SPAN, nel mio caso A) per impostare la lunghezza del box con la proprietà width dell'oggetto style riferito al box (in-line CSS); oppure utilizzando il metodo SetAttribute.
In entrambi i casi non ho ottenuto nulla...
Ecco un esempio:
codice:
<html>
<body>
<div style="background-color: #ddd;">
<span>
Ciao
</span>
</div>
<script type="text/javascript">
<!--
var box = document.getElementsByTagName("box")[0];
var span = document.getElementsByTagName("span")[0];
var len = span.offsetWidth;
box.style.width = len + 'px';
box.setAttribute( "style", "width: " + len + "px;" );
//-->
</script>
</body>
</html>