reactjs - 如何在 React 中指定多个宽度
问题描述
我有下一行代码,我指定内联 CSS,问题是宽度属性。
<li style={{ display: "inline-block", listStyle: "none", width: "-webkit-fill-available" }}>
我还需要指定 Firefox 内联宽度 -moz-fit-content 但我不知道语法,我已经尝试过了。
<li style={{ display: "inline-block", listStyle: "none", width: "-webkit-fill-available", width: "-moz-fit-content " }}>
但它不起作用。
解决方案
您可以在 css 中使用具有相同属性的类,并改用 className。
这是一个例子:
class SampleApp extends React.Component {
render() {
return (<div className={'foo'}>foo</div>);
}
}
ReactDOM.render(<SampleApp />, document.querySelector("#app"));
.foo {
width: 50px;
width: -webkit-fill-available;
width: -moz-fit-content;
/* not important */
background-color: #f4f4f4;
border: 1px dashed #ccc;
padding: 10px;
box-sizing: border-box;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="app"></div>
推荐阅读
- go - Golang 参数函数
- java - 解析来自 PDF417 内置阅读器 Android 设备的输入
- javascript - 如何使文本以曲线运动在屏幕上向上移动
- excel - VBA Excel - 从模块中的程序中收集用户表单中的数据
- vue.js - 使用 asyc 和 Vue 登录 Twitch API
- python - Pandas - 导入 CSV 问题 - 在末尾添加和删除 0
- asp.net-mvc - .Net Core App 中的 TinyMce - 上传后弹出窗口关闭
- ios - iOS Swift 可解码:错误:无法为没有参数的类型调用初始化程序
- node.js - 流如何使用 Azure Blob createReadStream 处理回调?
- ios - 有没有办法以编程方式检测 USB 以太网适配器是否连接到 iPhone/iPad?