网上的方法很多,但都有局限性,本文提供的方法基本兼容主流浏览器。
以HotNews主题为例。打开HotNews主题HotNewspro\js目录的custom.js把下面代码加到最后:
- // 控制图片大小
- $(document).ready(function() {
- var maxwidth=580;
- $(".entry p img").each(function(){
- if (this.width > maxwidth)
- this.width = maxwidth;
- });
- });
再打开主题样式文件style在最后添加:
- .entry p img{
- height: auto;
- }
也可单独使用Javascript或者CSS控制图片大小,不过兼容性较差
javascrip:
- <script type="text/javascript">
- $(document).ready(function() {
- var maxwidth=580;
- var maxheight=450
- $(".entry p img").each(function(){
- if (this.width > maxwidth)
- this.width = maxwidth;
- if (this.height > maxheight)
- this.height = maxheight;
- });
- });
- </script>
CSS:
- .entry p img{
- max-width: 90%;
- height: auto;
- }
其它主题可以将上述代码中的 .entry 改为所用主题选择器。
编辑文章时手动将插入的图片拖小,个人认为一劳永逸。
本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!

我的微信
微信号已复制
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!




