Reactjs 选择符之前/之后是否支持::before/::? 我试图用中间的文字来设置水平规则。它看起来是这样的:
Reactjs 选择符之前/之后是否支持::before/::? 我试图用中间的文字来设置水平规则。它看起来是这样的:,reactjs,emotion,Reactjs,Emotion,--------------------------一些文本------------------------------------------ 我在StackOverflow上找到了一些关于如何使用CSS实现这一点的示例,但它对我不起作用 这是我正在使用的DIV,但它不起作用 这是否可以设置为反应情绪?我错过了什么 一些文本 您的代码关于::before和::after语法是正确的, 但是,在尝试复制时,我发现了两个错误: flexGrow不应该有px单元,只要1:flexGrow:'1 内
--------------------------一些文本------------------------------------------
我在StackOverflow上找到了一些关于如何使用CSS实现这一点的示例,但它对我不起作用
这是我正在使用的DIV,但它不起作用
这是否可以设置为反应情绪?我错过了什么
一些文本
您的代码关于::before
和::after
语法是正确的,
但是,在尝试复制时,我发现了两个错误:
flexGrow:'1
content:“”“”
您需要通过emotion/css或emotion/react在css函数中传递样式对象 您忘了将样式化对象包装在函数中 如果使用的是对象而不是字符串,则将内容用双引号括起来
// First way, use css from @emotion/css, pass as object
import { css } from '@emotion/css'
<div
className={css({
display: 'flex',
lineHeight: '1em',
color: 'gray',
':before, :after': {
content: '""',
flexGrow: '1',
marginTop: '0.5em',
backgroundColor: 'gray',
height: '1px',
marginRight: '10px',
marginLeft: '10px'
}
})}
>
SOME TEXT
</div>
// Second way, use css from @emotion/css, pass as string
import { css } from '@emotion/css'
<div
className={css`
display: flex;
line-height: 1em;
color: gray;
:before, :after: {
content: '';
flex-grow: 1;
margin-top: 0.5em;
background-color: gray;
height: 1px;
margin-right: 10px;
margin-left: 10px;
}
`}
>
SOME TEXT
</div>
// Third way, use css from @emotion/react
import { css } from '@emotion/react'
<div
css={css`
display: flex;
line-height: 1em;
color: gray;
:before, :after: {
content: '';
flex-grow: 1;
margin-top: 0.5em;
background-color: gray;
height: 1px;
margin-right: 10px;
margin-left: 10px;
}
`}
>
SOME TEXT
</div>
//第一种方式,使用@emotion/css中的css,作为对象传递
从“@emotion/css”导入{css}
一些文本
//第二种方法,使用@emotion/css中的css,作为字符串传递
从“@emotion/css”导入{css}
一些文本
//第三种方法,使用@emotion/react中的css
从“@emotion/react”导入{css}
一些文本
// First way, use css from @emotion/css, pass as object
import { css } from '@emotion/css'
<div
className={css({
display: 'flex',
lineHeight: '1em',
color: 'gray',
':before, :after': {
content: '""',
flexGrow: '1',
marginTop: '0.5em',
backgroundColor: 'gray',
height: '1px',
marginRight: '10px',
marginLeft: '10px'
}
})}
>
SOME TEXT
</div>
// Second way, use css from @emotion/css, pass as string
import { css } from '@emotion/css'
<div
className={css`
display: flex;
line-height: 1em;
color: gray;
:before, :after: {
content: '';
flex-grow: 1;
margin-top: 0.5em;
background-color: gray;
height: 1px;
margin-right: 10px;
margin-left: 10px;
}
`}
>
SOME TEXT
</div>
// Third way, use css from @emotion/react
import { css } from '@emotion/react'
<div
css={css`
display: flex;
line-height: 1em;
color: gray;
:before, :after: {
content: '';
flex-grow: 1;
margin-top: 0.5em;
background-color: gray;
height: 1px;
margin-right: 10px;
margin-left: 10px;
}
`}
>
SOME TEXT
</div>