Sunday, September 25, 2011

Center Text AND Images Within ASP .NET

I recently integrated the handy AddThis sharing and analytics tool into an ASP .NET site I'm working on.

Whether due to peculiarities of the markup or browser idiosyncrasies, I couldn't get the widget consistently centered. The widget code lives in a div tag, and despite a popular few suggestions, I simply couldn't get things centered horizontally.

Centering text is no big deal; simply applying a CSS style usually does this well enough:

text-align: center;

Images, however, aren't accounted for by this markup. 

I ended up enclosing the widget in a Table control with the HorizontalAlign attribute specified to "Center", and this did the trick.


Much easier to allow ASP .NET to handle the grunt work of emitting the necessary markup in this case than messing (directly) with styles.

No comments: