css - CSS未在反应组件中呈现
问题描述
当我在 App.css 中应用下面的 CSS 时,它们会完美呈现,但是当我直接在我的组件(下)中应用相同的样式时,CSS 不会呈现。
const getStyles = () => {
const BLACK = "#000000";
const VW = "vw";
const VH = "vh";
const REM = "rem";
return {
editor: {
width: `70${VW}`,
height: `50${VH}`,
margin: `2${REM}`,
padding: `1${REM}`,
fontSize: `1.2${REM}`,
boxShadow: `0 .1${REM} .4rem ${BLACK}`,
border: `1px solid ${BLACK}`,
overflowY: `auto`
}
};
};
const styles = getStyles();
return (
<>
<div className="center">
<div className={styles.editor} contentEditable={true} suppressContentEditableWarning={true}>
<h1>{introText}</h1>
<p>{subText}</p>
</div>
</div>
</>
)
}
解决方案
为了得到你想要的效果,你应该做这样的事情。
const getStyles = () => {
const BLACK = "#000000";
const VW = "vw";
const VH = "vh";
const REM = "rem";
return {
width: `70${VW}`,
height: `50${VH}`,
margin: `2${REM}`,
padding: `1${REM}`,
fontSize: `1.2${REM}`,
boxShadow: `0 .1${REM} .4rem ${BLACK}`,
border: `1px solid ${BLACK}`,
overflowY: `auto`
};
};
const styles = getStyles();
return (
<>
<div className="center">
<div style={styles.editor} contentEditable={true} suppressContentEditableWarning={true}>
<h1>{introText}</h1>
<p>{subText}</p>
</div>
</div>
</>
)
}
此链接的更多信息:
推荐阅读
- php - SQL语句中变量中的撇号
- c - 插入二维字符数组后在 C 中打印的错误结果
- python - 我在使用 for 循环时遇到语法错误
- android - 无法在 Fragment 中设置 NumberPicker
- bash - 在 Bash 中形成选择查询
- django - 分页器对象没有属性“get_page”
- javascript - 使用 React 和 Web Audio 进行状态管理
- php - 成功 localhost 安装 Wordpress 后,找不到错误 404 对象。使用 Xampp 并在 Mac 上工作
- javascript - 尝试使用 JS 提交表单时无法 POST
- r - Rcpp中的滚动求和函数