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

overme7个月前 (10-17)网页设计1209
如下图所示,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默认的帖子内容页标题格式中,带有版块名称. 这样的内容页标题结构,导致标题过长,百度等搜素引擎收录时,标题看不到站点名称. 如何去除标题中的版块名称呢? 试着修改h...

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

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


		Discuz 手动安装bshare分享按钮

Discuz 手动安装bshare分享按钮

replyreload += ',' + 330;之前百度网页分享按钮未停用前,很多站都使用的百度网页分享,本站也是。 现在百度网页分享功能停用了,小编就转而使用bshare网页分享工具。 在此分...


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

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

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

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

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

Discuz关闭前台插件的更新提示教程

Discuz论坛系统,管理员每次登录论坛,遇到后台有没有更新的应用时,都会出现更新提醒,而且关了还会继续弹出。如下图所示,后台没有暂停更新提醒的选项,用户体验不是很好: 找到文件source/m...

发表评论

访客

看不清,换一张

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