day8: CSS style 规划 - CSS in JS(emotion 使用 - 2)

使用 react 作法

npm i @emotion/react
import { css, jsx } from '@emotion/react'

const color = 'white'

render(
  <div
    css={css`
      padding: 32px;
      background-color: hotpink;
      font-size: 24px;
      border-radius: 4px;
      &:hover {
        color: ${color};
      }
    `}
  >
   Demo
  </div>
)

使用这种方式的 css, 最终 css``` 不会产生一个新的 className, 会直接对 element 做 style 的附加,如果css ``` 经由父传子,且有相同的 css 属性,则後者会盖掉前者。

import { jsx } from '@emotion/react'

const Child = props => (
  <p
    css={css`
      margin: 0,
      fontSize: 12,
      lineHeight: 1.5,
      fontFamily: 'Sans-Serif',
      color: black`
    }
  />
)

const Parent = props => (
  <Child
    css={
     css`
		  fontSize: 14,
		  fontFamily: 'Georgia, serif',
		  color: darkgray
		 `
   }
  />
)
import { jsx } from '@emotion/react'

const Child = props => (
  <p
    css={css`
      margin: 0;
      fontSize: 12;
      lineHeight: 1.5;
      fontFamily: 'Sans-Serif';
      color: black;`
    }
  />
)

const Parent = props => (
  <Child
    css={
     css`
		 fontSize: 14;
		 fontFamily: 'Georgia, serif';
		 color: darkgray;
	   `
   }
  />
)

// 最後 Child 剩下的 style 

{
  *fontSize: 14;* //被删除
  *fontFamily: 'Georgia, serif';* //被删除
  *color: darkgray;* //被删除
  margin: 0;
  fontSize: 12;
  lineHeight: 1.5;
  fontFamily: 'Sans-Serif';
  color: black;
}


<<:  [想试试看JavaScript ] 阵列一些操作阵列好用的方法

>>:  新新新手阅读 Angular 文件 - Component - Day23

DAY 17 『 Xib 画面跳转 - push 、 present 』

push 刻好画面後,在 ViewController.swift ( MainVC.swift )...

最短路径问题 (1)

9.4 关於三连通的练习题 这题超难,我把连结放这边就好。 https://acm.timus.ru...

[day28] 更新购物车内品项

昨天有改了Products表格,先换一下 -- Table: public.products -- ...

[Day 8] Leetcode 1189. Maximum Number of Balloons (C++)

前言 飙车回家又是11点多了,发现今天的daily challenge是easy就顺手解个吧!题目在...

Media queries

为什麽需要 Media Queries Media queries 可以让我们依据不同装置的特性来调...