在后台返回数据的时候,把需要展示的富文本通过 str_replace 处理一下
给富文本中的图片和段落加上样式,在小程序中设置要实现的样式。
后端代码:
$detail['content'] = str_replace('<img','<img class="richImg"', $detail['content']);
$detail['content'] = str_replace('<p','<p class="tui-article"',$detail['content']);
小程序端样式:
.richImg{
max-width:100% !important;
height:auto;
display:block;
margin-top:8px;
}
.tui-article {
font-size: 30rpx;
padding-bottom: 10rpx;
line-height: 60rpx;
text-align: justify;
text-indent: 2em;
word-break: break-all;
word-wrap: break-word;
}