加载jquery后,无法在div内居中放置图像

编程入门 行业动态 更新时间:2024-10-25 22:31:11
本文介绍了加载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内居中放置图像

本文发布于:2023-10-07 23:51:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   加载   jquery   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!