Discuz论坛帖子内容图片水平居中的实现方法

overme7个月前 (10-17)网页设计1041
如下图所示,Discuz论坛默认发的帖子,是靠左对齐的。尝试通过Css text-align:center的样式控制图片水平居中,但是没有效果。

最后实现方法:修改2处Discuz文件

文件位置: template/default/forum/discuzcode.htm和 template/default/common/module.css。 如果你已经修改了模板,请打开对应模板的上述文件。
修改的方法:

1、找到258行以下代码:
<img{if $attach[‘price’] && $_G[‘forum_attachmentdown’] && $_G[‘uid’] != $attach[‘uid’]} class=”attprice”{/if} style=”cursor:pointer” id=”aimg_$attach[aid]” aid=”$attach[aid]” src=”{STATICURL}image/common/none.gif” zoomfile=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yeshumb=yes{else}{$attach[url]}$attach[attachment]{/if}” file=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}” inpost=”1″{if $_GET[‘from’] != ‘preview’}{/if} />

修改为:
<div style=”text-align:center;”><img{if $attach[‘price’] && $_G[‘forum_attachmentdown’] && $_G[‘uid’] != $attach[‘uid’]} class=”attprice”{/if} style=”cursor:pointer” id=”aimg_$attach[aid]” aid=”$attach[aid]” src=”{STATICURL}image/common/none.gif” zoomfile=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yeshumb=yes{else}{$attach[url]}$attach[attachment]{/if}” file=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}” inpost=”1″{if $_GET[‘from’] != ‘preview’}{/if} /></div>

2、找到260行的以下代码:
<img{if $attach[‘price’] && $_G[‘forum_attachmentdown’] && $_G[‘uid’] != $attach[‘uid’]} class=”attprice”{/if} id=”aimg_$attach[aid]” aid=”$attach[aid]” src=”{STATICURL}image/common/none.gif” zoomfile=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yeshumb=yes{else}{$attach[url]}$attach[attachment]{/if}” file=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}” $widthcode id=”aimg_$attach[aid]” inpost=”1″{if $_GET[‘from’] != ‘preview’}{/if} />

修改为:
<div style=”text-align:center;”><img{if $attach[‘price’] && $_G[‘forum_attachmentdown’] && $_G[‘uid’] != $attach[‘uid’]} class=”attprice”{/if} id=”aimg_$attach[aid]” aid=”$attach[aid]” src=”{STATICURL}image/common/none.gif” zoomfile=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yeshumb=yes{else}{$attach[url]}$attach[attachment]{/if}” file=”{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}” $widthcode id=”aimg_$attach[aid]” inpost=”1″{if $_GET[‘from’] != ‘preview’}{/if} /></div>

文件修改后上传到你的服务器,更新缓存后查看文章,发现图片已经水平居中了。

但是又发现一个问题,本地上传的图片可以水平居中,但是上传的网络图片,仍然是靠左对齐。该如何解决这个问题呢?

游客,如果您要查看本帖隐藏内容请回复

通过在img标签外加一个div包裹配合text-align:center,实现网络图片水平居中显示。

相关文章


		Discuz相关帖子功能开启方法

Discuz相关帖子功能开启方法

Discuz系统相同帖子功能,是非常不错的功能,可以根据标签,匹配相关内容供用户浏览. 如下图示: 在此分享相关帖子功能开启方法: 步骤1: 进入后台 -> 界面 ->界面设置-&...

如何去掉Discuz标题中的Powered by Discuz

使用Discuz系统的网站,默认每个页面标题后面会出现”Powered by Discuz!“字样的信息,使得页面标题比较冗长。 为优化标题结构,在此分享Discuz标题结构优化方法。 操作方法如...


		手机访问discuz网站 自动跳转手机版域名

手机访问discuz网站 自动跳转手机版域名

1. 前往域名服务商后台,对需要添加的手机域名进行解析 比如:m.5izixue.com 2. 二级域名解析后,登录Discuz 后台,进入域名设置,填写手机域名信息 3. 以上两步设置完后,输入...

Discuz建站系统default目录结构说明

/template/default/common/  公共模板目录全局加载 /template/default/common/block_forumtree.htm  DIY论坛树形列表模块 /t...

Discuz密码错误15分钟后登陆解决方法

使用Discuz建网站时,会遇到这样的问题,就是当用户密码输错5次之后,Discuz就会提示“密码错误次数过多,请15分钟后登陆”。怎么解决这样的问题呢? 下面介绍一下Discuz“密码错误次数过...


		Discuz去除图片下载附件提示信息

Discuz去除图片下载附件提示信息

使用Discuz建站系统发布帖子内容时,内容有图片时。鼠标移动到图片上时,会弹出下图所示的“下载附件”的提示信息。 实际大家浏览网页时,基本上是不会主动下载图片的,只是查看而已。但是,下载附件的提...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。