有时候画面的比例,会影响 CSS 显示的效果,而在 SASS 中,我们可以用数学的运算公式去调整 style 中的内容,让设计样式更加聪明的去适应画面。基本可运用的运算子像是 +, -, *, /, % 都可以用作 SASS 的计算。
// operator.sass
$deep-blue: #00beb5
$primary-button-color: #007ea5
$main-width: 960px
.container
background-color: $deep-blue
padding: 10px
width: $main-width
button
color: $primary-button-color
font-size: 24px
padding: 16px
width: $main-width*7/10
height: 100%
.button-small
font-size: 12px
padding: 8px
width: $main-width*3/10
首先,订定一个固定大小的 container,练习运用运算子,排版一组 button,让他们能够依照比例排列在同一行中。
container 的大小用参数订为 960 px,如果之後有要统一更改大小,也可以从参数一次改,不用到下面其他 class 中去改 property。
在 container 下的 button 做一些基本的设置,并且於 width 运算,将 main-width 切分为十分之七。
另设一个小 button class 他会继承原本的 button 样式,并且有套用到这个 class 的 button 会再加上 small 的其他设定,width 的部分切分为十分之三。
// App.js
import "./App.css";
import "./assets/sass/operator.sass";
function App() {
return (
<div className="App">
<div className="container">
<button>click me !</button>
<button className="button-small">click me !</button>
<button className="button-small">click me !</button>
<button>click me !</button>
</div>
</div>
);
}
export default App;
之後在 App.js 中引入 sass,然後放几颗 button 来试试看效果。
就会获得完美分配好的 button ~
虽然要切分 column 的话,我会偏好使用 grid 系统去切,比较快,但是有时候遇到奇数或是要特别份数的 column 的时候,直接针对 css 去做计算其实是比较方便的,但两种方法有利有弊,就看大家选择怎麽使用罗!
除此之外,也欢迎大家走走逛逛关於我们团队夥伴的文章
juck30808 - Python - 数位行销分析与 Youtube API 教学
SiQing47 - 前端?後端?你早晚都要全端的,何不从现在开始?
我会从文档中挑几个重要的出来讲,但不会是全部,我会着重一些基本的中间操作,异常,取消,dispatc...
以 PS1 和 PS2 称霸於前两个世代的 SONY、在新的世代推出的主机当然就叫做 PS3。然而身...
ML 就像孩子一样,孩提时百般呵护,长大时不得不面对外界的残酷。布署到商务情境的 ML 模型,某方面...
URL : https://app.hackthebox.eu/machines/14 IP : ...
Throw 例用关键字 throw 也可以自行抛出例外、错误讯息,除了可以抛出 Dart 预设的例外...