- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 emotion
在我的 React 应用程序中设计和显示复利方程式。我的 render()
返回这个:
<div css ={equation}>
<p>
P (1 +</p>
<p css={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)
<sup>(nt)</sup>
</div>
在我的组件之外我有:
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 12px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`
const equation = css`
font-size: 100%;
.p{
font-size:large !important;
}
`;
分数的样式正确。但是,我无法更改 p
元素的字体。我得到它的唯一方法是将 p
元素切换为 h1
元素 - 但我不想这样做。我希望能够在我的情感 CSS 样式中指定字体大小。
最佳答案
我注意到您的代码中存在一些问题。
.p { ...
在不是类选择器但应该是元素选择器的方程式中 p { ...
div
必须使用 className
为了使这种效果应用这里是沙箱代码更改:https://codesandbox.io/s/emotion-xh53z?fontsize=14
只是复制在这里供您引用:
import React from "react";
import { render } from "react-dom";
import { css } from "react-emotion";
const fraction = css`
display: inline-block;
position: relative;
vertical-align: middle;
letter-spacing: 0.0001em;
text-align: center;
.num {
display: block;
padding: 0;
height: 30px;
line-height: 12px;
}
.bottom {
border-top: thin solid black;
}
.symbol {
display: none;
}
`;
// Notice the p inside the equation
const equation = css`
p {
font-size: large !important;
}
`;
// Rather than css={}, you should be using className={}
const App = () => (
<div className={equation}>
<p>
P (1 +
<p className={fraction}>
<span className="num">1</span>
<span className="symbol">/</span>
<span className="bottom">2</span>
</p>
)<sup>(nt)</sup>
</p>
</div>
);
render(<App />, document.getElementById("root"));
我也动了收盘</p>
最后标记以确保按照 inline-block
应用它
更新 1:
这是最新的更新版本:https://codesandbox.io/s/emotion-1tjc7
根据他们最新的 blog你应该使用:
import styled from '@emotion/styled'
import { css } from 'emotion'
而不是 import styled, { css } from 'react-emotion'
更新 2:
如果你不能使用 Vanilla 情感,那么你可以考虑使用以下:
import styled from "@emotion/styled";
/** @jsx jsx */
import { css, jsx } from "@emotion/core";
根据他们的 documentation :
有两种方法可以开始使用 css 属性。
我已经更新了相同的codesandbox:https://codesandbox.io/s/emotion-0z3vz
关于css - react 和情感 : Specify font size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58278937/
我正在使用reactjs-popup,它的 Prop 之一是contentStyle,它允许您传递css-in-js对象来设置库中内部div的样式。 但是,当我传递带有 @media 的 css 对象
在查看了一些服务/工具之后,我得出了一个结论。大多数 Text-to-Speech 工具的技术含量太高、太机械化——换句话说,就是质量差的 c 语音。 是的,最重要的是,看起来它们带有“硬编码”语音模
我正在尝试使用 Emotion.sh在我的 React 测试元素中,但我使用与 example 中相同的代码得到以下错误 需要考虑的可能有冲突的事情:1、之前用的是npm,现在用的是yarn;2. 我
通过以下链接,我有了一些想法。我想问问我是做对了还是做错了。如果我走错了路,请指导我。 链接 Using libsvm for text classification c# How to use li
以下设置不显示background-image。作为调试步骤,我尝试在 const background 中设置 background: pink,这确实有效,确认 emotion 正在正确运行。 打
我有一个 data.frame,其中包含周数 week 和文本评论 text。我想将 week 变量视为我的分组变量,并对它运行一些基本的文本分析(例如 qdap::polarity)。一些评论文本有
我正在研究 Kaggle 电影情感分析,我发现电影评论已使用 Standford Parser 进行了解析。在探索数据集时,我发现相同的语句给出了不同的设置- their parents , wise
我正在尝试使用Affectiva emotion sdk 制作一个演示程序。但是,当我调用 detector.setLicensePath() 时,会抛出一个异常(见下图)。有谁知道如何解决这个问题?
我想设置一个使用 Material-UI v4.11.4 的 Typescript 项目来使用情感进行样式设置,为 MUI v5 版本做准备。目标是在项目中引入情感,以便开发人员可以开始使用新样式,而
我是一名优秀的程序员,十分优秀!