加载HTML富文本详情

// 使用 rich-text 加载富文本数据
<rich-text class="richText" :nodes="nodes"></rich-text>
一 .对 H5 中的详情
  1. 自适应HTML内容 中的图片大小.
// 全局搜索并替换图片样式
 this.nodes = this.item.content.replace(/<img/gi,'<img style="max-width:100%;height:auto;margin:0 auto;display:block"')
  1. 使用增加权重的方式, 修改 HTML 内容中的字体样式.
    .richText {
        padding: 0rpx 30rpx 0rpx 30rpx;
        // line-height:1.667em;
        // letter-spacing:0.5px;
        text-align:justify;
        word-break: break-all;
        p{
            font-size: 32rpx !important;
            // text-indent: 2em !important;
            text-align: justify !important;
            color: #333333 !important;
            line-height:1.667em !important;
            letter-spacing:0.5px !important;
            word-break: break-all !important;
            // margin-bottom: 28rpx !important;
        }
        span{
            font-size: 32rpx !important;
            text-indent: 2em !important;
            text-align: justify !important;
            color: #333333  !important;
            line-height:1.667em !important;
            letter-spacing:0.5px !important;
            word-break: break-all !important;
        }
    }
二. 对于微信小程序

.1. 自适应HTML内容 中的图片大小.

// content 为后端返回的富文本内容
formatImg(content) {
    if (!content) return '';
        const regex = /<img[^>]*>/g;
        content = content.replace(regex, function(match) {
        return match.replace('>', 'style="max-width:100%;height:auto;">');
        });
    return content;
},
  1. 直接使用class增加权重的方式, 修改 HTML 内容中的字体样式
    .richText {
        padding: 0rpx 30rpx 0rpx 30rpx;
        // line-height:1.667em;
        // letter-spacing:0.5px;
        text-align: justify;
        word-break: break-all;

        font-size: 32rpx !important;
        // text-indent: 2em !important;
        text-align: justify !important;
        color: #333333 !important;
        line-height: 1.667em !important;
        letter-spacing: 0.5px !important;
        word-break: break-all !important;
        // color: red !important;
        // margin-bottom: 28rpx !important;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,806评论 1 92
  • 本文主要讲述页面布局样式方面涉及的知识点,更全面的对CSS相应的技术进行归类、整理、说明,没有特别详细的技术要点说...
    Joel_zh阅读 925评论 0 1
  • 测试文本数据 //html标签图片自适应 NSString *detailTextString = [STNews...
    小涛_78e8阅读 1,259评论 2 5
  • HTML总结 sublime 环境配置 使用sublime text 3 打开百度在搜索框中输入sublime t...
    Viarotel阅读 486评论 0 0
  • 前端开发面试题 面试题目: 根据你的等级和职位的变化,入门级到专家级,广度和深度都会有所增加。 题目类型: 理论知...
    怡宝丶阅读 2,609评论 0 7