Tuesday, January 26, 2010

ASP.Net and style=”display:inline-block”

I found ASP.Net was throwing in a style=”display:inline-block” on some of my elements. This style element works fine in IE – but was hosing up the display of content in Chrome and FireFox. Turns out that ASP.Net automatically injects that style element anytime you set the width or height on an ASP.Net control.

Easy and recommended fix: remove the height and width being set on the control and instead use a CSS style to assign the dimensions.

Complicated fix: over-ride the render method on the control.

3 comments:

jamieyates79 said...

Thanks for this. I couldn't understand why I was getting the 'display: inline-block' inserted into the HTML displaying a Grid control :)

Mike, Zhang Mingquan said...

When did this start to happen?

There is no such problem before.

Unknown said...

alternatively you can try this:

control.Style.Add("width", "45");