作用域

全局

<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 

nextjs —— jsx style 学习记录的更多相关文章

  1. 开源项目Material Calendar View 学习记录 (一)

    开源项目Material Calendar View 学习记录 Github: https://github.com/prolificinteractive/material-calendarview ...

  2. jQuery Moblile Demos学习记录Theming、Button、Icons图标,脑子真的不好使。

    jQuery Moblile Demos学习记录Theming.Button.Icons图标,脑子真的不好使. 06. 二 / Jquery Mobile 前端 / 没有评论   本文来源于www.i ...

  3. D3.js学习记录【转】【新】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 我的three.js学习记录(二)

    通过上一篇文章我的three.js学习记录(一)基本上是入门了three.js,但是这不够3D,这次我希望能把之前做的demo弄出来,然后通过例子来分析操作步骤. 1. 示例 上图是之前做的一个dem ...

  5. 我的three.js学习记录(三)

    此次的亮点不是three.js的3d部分,而是通过调用摄像头然后通过摄像头的图像变化进行简单的判断后进行一些操作.上篇中我通过简单的示例分析来学习three.js,这次是通过上一篇的一些代码来与摄像头 ...

  6. V4L2学习记录【转】

    转自:http://blog.chinaunix.net/uid-30254565-id-5637600.html V4L2学习记录 这个还没有分析完,先在这放着,防止电脑坏掉丢了,以后再完善 V4L ...

  7. Echarts学习记录——如何去掉网格线及网格区域颜色

    关键属性 splitLine和splitArea,可以设置相关的属性 示例代码 <!DOCTYPE html> <html lang="en"> <h ...

  8. Echarts学习记录——如何给x轴文字标签添加事件

    Echarts学习记录——如何给x轴文字标签添加事件 关键属性 axisLabel下属性clickable:true 并给图表添加单击事件 根据返回值判断点击的是哪里 感觉自己的方法有点变扭,有更好办 ...

  9. Android学习记录(3)—Android中ContentProvider的基本原理学习总结

    一.ContentProvider简介        当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据.虽然使用其他方法也可以对外共享数据 ...

随机推荐

  1. linux-rsync-同步本地文件夹

    linux-rsync-同步本地文件夹 1.安装rsync: yum list rsync yum install rsync 3.使用rsync命令进行同步 rsync -av 源目录 目标目录

  2. [NPM错误]npm ERR! Unexpected end of JSON input while parsing near ‘’

    [错误描述] npm ERR! Unexpected end of JSON input while parsing near ‘  ’ [前提描述] 在安装vue2-editor时,中断暂停了,再次 ...

  3. code and dataset resources of computer vision

    From:http://rogerioferis.com/VisualRecognitionAndSearch2014/Resources.html Source Code Non-exhaustiv ...

  4. [转帖]Linux文件系统详解

    Linux文件系统详解 https://www.cnblogs.com/alantu2018/p/8461749.html 贼复杂.. 从操作系统的角度详解Linux文件系统层次.文件系统分类.文件系 ...

  5. python基础学习(十)

    21.文件操作 # r只读 w只写(原来文件会消失!!!,也可以创建新文件) a追 # 加 r+ 读写 story_file = open("Story.txt", "r ...

  6. 6.66 分钟,一文Python爬虫解疑大全教入门!

    我收集了大家关注爬虫最关心的  16 个问题,这里我再整理下分享给大家,并一一解答. 1. 现在爬虫好找工作吗? 如果是一年前我可能会说爬虫的工作还是挺好找的,但现在已经不好找了,一市场饱和了,二是爬 ...

  7. Python习题001

    作业1 * 用条件语句写一个BMI(体重除以身高的平方)指数* 低于18.5:过轻* 18.5 - 25 正常* 25 - 28 过重* 28 - 32 肥胖* 高于32 严重肥胖 weight = ...

  8. 几个有益的 CSS 小知识

    样式的顺序 CSS 代码:   HTML 代码:   记得之前这是一道比较火的 CSS 考题,当时好像是有不少的人答错(30% 以上) 答案你们应该是知道的. 可以这样提升 CSS 性能 后代选择器 ...

  9. python3 内置方法 字符串转换为字典

    内置方法:eval()将字符串转换为字典代码: str = '''{'backend':'www.oldboy.org', 'record':{ 'server':'122.111.2.23', 'w ...

  10. is 和 as 使用

    类型判断 as: var newParser = parser as ClassA ; 转为ClassA类型赋值给newParser is: var flag = parser is ClassA ; ...