本文介绍了加载jquery后,无法在div内居中放置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jquery动态加载图像,但似乎无法将它们放在div中.我的HTML看起来像这样:
I'm loading images dynamically with jquery and can't seem to center them inside the div. My HTML looks like this:
<div style="width:100%;border: solid 1px #ff0000;"> <img id="current_photo" src="" style="margin-right: auto; margin-left: auto;max-width:97%;"/> </div>jQuery调用看起来像这样:
The jQuery call looks like this:
$("#current_photo").attr('src', img_url); //$('#current_photo').css({'margin-right':'auto','margin-left':'auto'});我假设在图像加载后需要应用CSS,但这似乎也不起作用.
I'm assuming I need to apply the CSS after the image has loaded but this doesn't seem to work either.
无论我尝试什么,图像总是左对齐.知道会发生什么吗?
No matter what I try the images are always left justified. Any idea what might be happening?
推荐答案添加"text-align:center;"到您所在的div. 也不需要自动页边距.
Add "text-align:center;" to your containing div. Also no need for the auto margins.
更多推荐
加载jquery后,无法在div内居中放置图像
发布评论