css - 当html字符串已经有宽度时如何设置imagesMaxWidth
问题描述
我在开发 React Native 应用程序时使用 react-native-render-html 将字符串转换为 html 元素。<img>
我从后端通过 RESTful API 收到了字符串,并且标签中已经设置了宽度和高度:
<img class="aligncenter" src="https://www.allfin.com/u/cms/www/201811/13142949sf02.jpg" width="600" height="408" />
但我希望将图像调整为窗口的最大宽度,所以我使用:
imagesMaxWidth={Dimensions.get('window').width}
整个片段如下:
<ScrollView style={styles.content}>
<Text style={styles.title}>{this.props.title}</Text>
<Text>{this.props.date}</Text>
<HTML
html={this.props.content}
imagesMaxWidth={Dimensions.get('window').width - 40}
/>
</ScrollView>
但是图像无法调整到窗口的最大宽度。
那么我该如何设置呢?
谢谢
解决方案
使用ignoredStyles
prop 忽略原始图片的宽度和高度。用于ignoredStyles={['height', 'width']}
解决问题。
推荐阅读
- vue.js - Vue - 我如何在组件模板中呈现脚本?
- openlayers - OpenLayers 3+:在地图上突出显示几公里
- python - 有没有办法优化这个 python 尝试,除了循环?
- c++ - 将模板类型限制为枚举类
- json - 角度http帖子内容类型应用程序/ json不工作
- angular - Angular Firebase 无法连接到 AngularFireDatabase
- python - 我正在尝试用 gekko 解决非线性混合整数问题,我正在进入一个循环
- r - 按非列 X 分组
- flutter - 颤振:强制容器高度为孩子的高度
- delphi - 如何等待并读取来自 Indy TCP 套接字的所有可用数据?