Reputation: 187
I have many li
s under ul
. I have written here my first image which I pass source in javascript dynamically. My image is left aligned, I need it to be centered.
$("#imgemp").attr("src", src);
<ul>
<li class="imgli">
<img id="imgemp" border="0" width="90" height="90">
</li>
</ul>
Upvotes: 2
Views: 100
Reputation: 68393
Assuming your li
's width
is big enough (more than 90) than text-align:center
should do it.
<li class="imgli" style='width:200px;text-align:center;' >
<img id="imgemp" border="0" width="90" height="90">
</li>
Upvotes: 1
Reputation: 503
You have already appended imgli
class to li
. Why not just use this?
.imgli{
text-align: center;
}
Upvotes: 1
Reputation: 18754
image
is an inline element so you can use text-align:center
.
$("#imgemp").attr("src", src);
li {
text-align: center
}
<ul>
<li class="imgli">
<img id="imgemp" border="0" width="90" height="90">
</li>
</ul>
Upvotes: 1