공부하면서 계속 추가할 예정 👩🍳💕
CSS에 programming 요소를 한스푼 얹은... 😉
$main-color : red;
$main-color: black;
.content {
color: $main-color // black
}
.aside {
$main-color: red;
color: $main-color // red
}
- 이렇게 명확하게 컬러 이름을 정할 수 없는 경우 (grayscale):
1) gray-1
여기서 1은 #121212의 앞글자의 1을 뜻한다
즉, 숫자가 커지면 커질수록 컬러는 옅어짐. 숫자 ~ 알파벳
단점: 디자이너가 컬러를 바꾸게 되면 변수명도 함께 바꿔야 됨.
2) primary (주로 본문 텍스트 기준)
해당 컬러가 사용되는 상황에 따라 이름을 지어줌
dark
, primary
, secondary
, tertiary
, border
, background
, white
3) 그 외 : 인터넷에서 보고 괜찮은거 찾아봄
https://codeandplayclub.com/docs/global-colors.html
변수 이름 TIP 👇
https://webdesign.tutsplus.com/articles/quick-tip-name-your-sass-variables-modularly--webdesign-13364
line-height
와 letter-spacing
이 잘 지켜지지 않은 채 퍼블리싱이 되는 경우가 많음! (제각각인 경우도 있고?)$font-size-12: 12px;
$line-height-12: 16px;
$letter-spacing-12: -0.005em;
line-height
와 letter-spacing
을 유추할 수 있도록 함.$font-main: 'Roboto', sans-serif;
$font-price: 'Noto Sans KR', sans-serif;
Selectors in style rules
Property names in declarations
Custom property values
CSS at-rules
@extends
Plain CSS @imports
Quoted or unquoted strings
Special functions
Plain CSS function names
Loud comments
$bold: 600;
$font-size: 16px;
$line-height: 32px;
p.#{$bold}{ //셀렉터
font-weight: $bold;
font: #{$font-size} / #{$line-height}; // 16px / 32px
// 의도대로 연산되지 않고 제대로 출력됨.
}
ul {
display: flex;
li { background-color: yellow; }
a { display: block; }
}
&
를 사용한다.nested selector
에 사용된다.&
키워드로 대신 사용된다./* AS-IS : CSS */
button,
a {
background-color: #000;
}
button:hover,
a:hover{
background-color: #eee;
}
:not(button),
:not(a){
opacity: 0.8;
}
/* TO-BE : SCSS*/
button,
a {
background-color: #000;
&:hover {
background-color: #eee;
}
:not(&) {
opacity: 0.8;
}
}
/* AS-IS : CSS */
.accordion {
max-width: 600px;
margin: 4rem auto;
width: 90%;
font-family: "Raleway", sans-serif;
background: #f4f4f4;
}
.accordion__copy {
display: none;
padding: 1rem 1.5rem 2rem 1.5rem;
color: gray;
line-height: 1.6;
font-size: 14px;
font-weight: 500;
}
.accordion__copy--open {
display: block;
}
/* TO-BE : SCSS*/
.accordion {
max-width: 600px;
margin: 4rem auto;
width: 90%;
font-family: "Raleway", sans-serif;
background: #f4f4f4;
&__copy {
display: none;
padding: 1rem 1.5rem 2rem 1.5rem;
color: gray;
line-height: 1.6;
font-size: 14px;
font-weight: 500;
&--open {
display: block;
}
}
}
%
를 활용하여 선택할 수 있다..alert:hover, %strong-alert {
font-weight: bold;
}
/*
* CSS OUTPUT : placeholder는 바로 보이지 않음.
*/
.alert:hover {
font-weight: bold;
}
@extend
키워드를 사용한다.%button {
padding: 10px 20px;
border-radius: 5px;
transition: all .5s linear;
&:hover {
opacity: .8
}
}
.alert-btn{
@extend %button;
background-color: red;
}
@extend
관련 글은 At-Rules에 더 적을 예정!@mixin reset-list {
margin: 0;
padding: 0;
list-style: none;
}
@mixin horizontal-list {
@include reset-list;
li {
display: inline-block;
margin: {
left: -2px;
right: 2em;
}
}
}
nav ul {
@include horizontal-list;
}
/****************************************/
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav ul li {
display: inline-block;
margin-left: -2px;
margin-right: 2em;
}
@mixin font ( $fontsize, $fontweight, $color ){
font-size: $fontsize;
font-weight: $fontweight;
color: $color;
}
.container {
@include font(12,bold,black)
}
@mixin hover {
&:hover {
@content;
}
}
.button {
border: 1px solid black;
@include hover {
border-width: 2px; //값이 block형태 내에 들어가게 됨.
}
}
-이 역시 @mixin처럼 function화 한다. 다만 다른점은 @function의 경우 값을 리턴해야 한다.
@function _px($num) {
@return $num + px;
}
em {
font-size: _px(12);
}
$var: value
.@if
, @each
, @for
, @while
@error
, @warn
, and @debug
rules.@return
@extend
를 사용한다.@extend
유무에 따른 다른 점placeholder
와도 함께 사용 가능 → 관련 내용은 상단에@media
에서 사용 가능. 단, @extend
를 하는 선택자는 @media
안에 존재해야 된다. → 안쓰는게 나을거 같고, 사용방법을 읽어보면 @media
에 사용할 이유도 굳이 없다./*
* 1. @extend 사용
*/
.error {
border: 1px #f00;
background-color: #fdd;
&--serious {
@extend .error;
border-width: 3px;
}
}
.error, .error--serious { /* 공통 스타일 적용 */
border: 1px #f00;
background-color: #fdd;
}
.error--serious {
border-width: 3px;
}
/*
* 2. @extend 미사용
*/
.error {
border: 1px #f00;
background-color: #fdd;
&--serious {
border-width: 3px;
}
}
.error {
border: 1px #f00;
background-color: #fdd;
}
.error--serious { /* 이름만 이어지고 공통 스타일 X */
border-width: 3px;
}
@extend
사용 시, pseudo-class
역시 함께 적용됨.error:hover {
background-color: #fee;
}
.error--serious {
@extend .error;
}
/* CSS OUTPUT */
.error:hover, .error--serious:hover {
background-color: #fee;
}
@mixin
과는 거의 비슷하지만 매개변수의 유무에 따라 둘 중 하나를 선택하면 되고 확장하는 개념이라고 생각될 때는 @extend
를 사용하는게 좋다.자바스크립트의 for문과 같은 기능을 제공함
@for <variable> from <expression> to <expression> { ... }
@for <variable> from <expression> through <expression> { ... }
to
키워드 사용시 마지막 숫자 불포함
through
키워드 사용시 마지막 숫자 포함
$base-color: #036;
@for $i from 1 through 3 {
ul:nth-child(3n + #{$i}) {
background-color: lighten($base-color, $i * 5%);
}
}
/****************************************/
ul:nth-child(3n + 1) {
background-color: #004080;
}
ul:nth-child(3n + 2) {
background-color: #004d99;
}
ul:nth-child(3n + 3) {
background-color: #0059b3;
}
@if <expression> { ... }
$light-background: #f2ece4;
$light-text: #036;
$dark-background: #6b717f;
$dark-text: #d2e1dd;
@mixin theme-colors($light-theme: true) {
@if $light-theme {
background-color: $light-background;
color: $light-text;
} @else {
background-color: $dark-background;
color: $dark-text;
}
}
.banner {
@include theme-colors($light-theme: true);
body.dark & {
@include theme-colors($light-theme: false);
}
}
math.percentage($number)
percentage($number)
$number * 100%
를 해주어 %
단위로 만들어 준다.maps 만들기
$font-weights: ( "regular": 400, "medium": 500, "bold": 700 );
map-get
map.get($map, $key, $keys...) map-get($map, $key, $keys...)
null
반환$font-weights: ("regular": 400, "medium": 500, "bold": 700);
@debug map.get($font-weights, "medium"); // 500
@debug map.get($font-weights, "extra-bold"); // null
📚 모든 글은 SCSS doc을 공부하고 난 후 작성합니다.
📚 이해가 안되는 부분은 하단의 웹사이트를 참고하였습니다.
https://poiemaweb.com/sass-script