Daft Daft - 29 days ago 7
CSS Question

Center text next to image in dynamically created div. jQuery

At the moment, the text is aligned with the top of the image. Is there any way for me to pad the text down so it is aligned with the center of the image?

Any padding I add to ui-title moves the entire div.

Or would I have to restructure the jQuery to achieve this?

pageDiv.append(
$('<div>').addClass('ui-title').text('hello').append(
$('<img class="confirm" src="image.png" alt="" height="30" width="30"></img>')
)
)

Answer

First off like the first comment says, there is no need for </img>. img tags can be self closing so you can change it to <img class="confirm" src="image.png" alt="" height="30" width="30" />.

Your looking to use vertical-align: middle; but you need to make sure the div containing your text is set to display: inline; or display: inline-block;.

Comments