标签:style const color padding nextjs background props jsx children
作用域
全局
<style global jsx>{` .hero { width: 100%; color: #333; } .title { margin: 0; width: 100%; padding-top: 80px; line-height: 1.15; font-size: 48px; } `}</style>
host scope
<div className="root"> <style jsx>{` .root { color: green; } `}</style> </div>
one-off global(只针对某个 css 全局)
import Select from 'react-select' export default () => ( <div> <Select optionClassName="react-select" /> <style jsx>{` /* "div" will be prefixed, but ".react-select" won't */ div :global(.react-select) { color: red } `}</style> </div> )
动态 style
① 行内 sytle
const Button = ({ padding, children }) => ( <button style={{ padding }}> { children } <style jsx>{` button { padding: 20px; background: #eee; color: #999 } `}</style> </button> )
② className 切换
const Button = (props) => ( <button className={ 'large' in props && 'large' }> { props.children } <style jsx>{` button { padding: 20px; background: #eee; color: #999 } .large { padding: 50px } `}</style> </button> )
③ jsx style 变量
const Button = (props) => ( <button> { props.children } <style jsx>{` button { padding: ${ 'large' in props ? '50' : '20' }px; background: ${props.theme.background}; color: #999; display: inline-block; font-size: 1em; } `}</style> </button> )
或(直接通过 js 引入常量)
import { colors, spacing } from '../theme' import { invertColor } from '../theme/utils' const Button = ({ children }) => ( <button> { children } <style jsx>{` button { padding: ${ spacing.medium }; background: ${ colors.primary }; color: ${ invertColor(colors.primary) }; } `}</style> </button> )
233
标签:style,const,color,padding,nextjs,background,props,jsx,children 来源: https://www.cnblogs.com/lemos/p/11221472.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。