CSS
問題
- 上下 margin 重疊時取最大值會失效的情況:
display: flex;
flex-direction: column;
技巧
-
撐開到最大螢幕高度:
min-height: 100vh;
-
CSS selector:
&:nth-child(odd)
,&:nth-child(n + 3)
-
overflow-x: hidden;
overflow 可以設定你的 scroll bar 要發生在哪裡 -
Flip an Image (or SVG)
transform: scaleX(-1);
https://css-tricks.com/snippets/css/flip-an-image/ -
scroll-snap-type
https://css-tricks.com/practical-css-scroll-snapping/ -
margin-right: auto
推到底的意思 -
svg 填色,選底下的 path 來填色
path {
fill: #c0cbcf;
}
-
Dark mode
filter: invert(1) hue-rotate(180deg);
https://dev.to/dip15739/dark-mode-with-only-1-css-property-17fl -
Disable scroll (modal 底下那層)
useEffect(() => {
document.body.style.overflow = 'hidden';
return () => {
document.body.style.overflow = null;
};
}, []);
原則
可以用 CSS 解決的,就不要用到 JS
不知道怎麼寫的時候,可以參考 Bootstrap 的 code
https://getbootstrap.com/docs/4.5/components/toasts/
* {
-webkit-tap-highlight-color: transparent;
}
(Learned by Add tap highlight color override style by project)
過場動畫 CSS
transition: border-color 0.5s;
transition-property: all;
transition-duration: 0.3s;
當你用 js 改 css 屬性的時候,中間的過場變化設定
https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property
https://www.w3schools.com/css/css3_transitions.asp
各種屬性
- box-shadow
You can set multiple effects separated by commas. - pointer-events
可以加pointer-events: none;
讓下層的 div 可以被 hover
https://www.oxxostudio.tw/articles/201409/pointer-events.html - cursor
default / pointer
http://developer.mozilla.org/en-US/docs/Web/CSS/cursor
Input
Loading spinner
https://www.w3schools.com/howto/howto_css_loader.asp
Progress Ring
https://css-tricks.com/building-progress-ring-quickly/
https://codepen.io/jeremenichelli/pen/gGWPme