首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React Native html渲染:图像问题

React Native html渲染:图像问题
EN

Stack Overflow用户
提问于 2020-03-01 00:07:34
回答 1查看 1.2K关注 0票数 1

我尝试从JSON端点加载HTML,并将其显示在应用程序中。这在使用一些库时效果很好,但是HTML内容在底部也包含图像。

这些图像堆叠在一起,而不是相邻的居中。

我怎样才能做到这一点呢?使用哪个模块最好呢?

下面是一个代码片段。不确定如何正确设置样式:(

代码语言:javascript
复制
"<p><strong><em>Title –</em></strong> This a little text.</p>\n<p>This a little text</p>\n<div id='gallery-4' class='gallery galleryid-114867 gallery-columns-4 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https://urltosite/2020/02/28/photo/photo_2020-02-28_19-38-38/'><img width=\"150\" height=\"150\" src=\"https://urltosite/wp-content/uploads/2020/02/photo_2020-02-28_19-38-38-150x150.jpg?v=1582915513\"; class=\"attachment-thumbnail size-thumbnail\" alt=\"\" /></a>\n\t\t\t</div></figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https://urltosite/2020/02/28/phtoto/photo_2020-02-28_19-38-42-2/'><img width=\"150\" height=\"150\" src=\"https://urltosite/wp-content/uploads/2020/02/photo_2020-02-28_19-38-42-1-150x150.jpg?v=1582915516\"; class=\"attachment-thumbnail size-thumbnail\" alt=\"\" /></a>\n\t\t\t</div></figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https://www.urltosite/2020/02/28/phtot/photo_2020-02-28_19-38-46/'><img width=\"150\" height=\"150\" src=\"https://urltosite/wp-content/uploads/2020/02/photo_2020-02-28_19-38-46-150x150.jpg?v=1582915518\"; class=\"attachment-thumbnail size-thumbnail\" alt=\"\" /></a>\n\t\t\t</div></figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https://urltosite/2020/02/28/photo/photo_2020-02-28_19-38-48/'><img width=\"150\" height=\"150\" src=\"https://urltosite/wp-content/uploads/2020/02/photo_2020-02-28_19-38-48-150x150.jpg?v=1582915521\"; class=\"attachment-thumbnail size-thumbnail\" alt=\"\" /></a>\n\t\t\t</div></figure>\n\t\t</div>\n\n"```
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-01 13:54:42

您可以使用react-native-render-html,并使用tagsStyles和classesStyles属性为每个html标记或类指定样式。下面的代码是使用此道具的示例:

代码语言:javascript
复制
<HTML
   html={item.message}
   tagsStyles={{
      p: {
          fontSize: 22,
          lineHeight: 30,
          marginBottom: 0
      },
      img: {
          ...
      }
   }}
   classesStyles={{
      'custom-image': { 
           ... 
      } 
   }}
   ignoredStyles={['line-height']} />

您还可以使用renderers属性来呈现特定标签的自定义内容。有关react-native-render-html的更多信息,请访问以下链接:https://github.com/archriss/react-native-render-html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60467082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档