A Javascript solution - not necessarily the best - would have to find out about div / p height and make a determination from there. You need to know the height that the DOM element takes if there is only one row. If the height exceeds this value, you do one; if not, you are doing something else. You would set your default CSS to a more common phenomenon and only change it in fewer cases.
For instance:
var tag = document.getElementById("id_here"); if(tag.offsetHeight > 18){ tag.style.textAlign = "left"; tag.style.whiteSpace = "normal";}
You can also use jQuery. Note that offsetHeight includes an add-on.
But you really don't need a Javascript solution. I canβt think how you will do it in CSS, mind you, because it is related to the dynamic style. I would strongly suggest that this is not possible.
source share