// External
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
// Internal
<head>
<style type="text/css">
.div-box {
color:red
}
</style>
</head>
// Inline
<p style="font-size: 15px;">15픽셀사이즈로 디자인됩니다.</p>
<style>
태그나 CSS 파일에서 나중에 나온것이 적용이 된다.위 같은 문제를 해결하고자 CSS 설계방법 및 규약(external 방식, BEM 표기 및 선택자를 클래스로만 제한 등) 등 방법들이 있으나 근본적으로 CSS 의 문제를 제한하기는 어려움
SASS, LESS Stylus 등이 CSS 전처리를 도와주는 도구다.
/* SCSS */
$primary-color: #3bbfce;
$secondary-color: #ff8700;
.content {
background-color: $primary-color;
color: darken($secondary-color, 9%);
}
// mixin
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box { @include border-radius(10px); }
$max-width: 980px;
// function
@function columns($number: 1, $columns: 12) {
@return $max-width * ($number / $columns)
}
.box_group {
width: $max-width;
.box1 {
width: columns(); // 1
}
.box2 {
width: columns(8);
}
}
/* SASS */
$primary-color: #3bbfce
$secondary-color: #ff8700
.content-navigation
background-color: $primary-color
color: darken($secondary-color, 9%)
=border-radius($radius)
-webkit-border-radius: $radius
-moz-border-radius: $radius
-ms-border-radius: $radius
border-radius: $radius
.box
+border-radius(10px)
Nesting Selectors :
.section { width: 100%; .list { padding: 20px; li { float: left; } } }
Nesting Properties :
.box { font: { weight: bold; size: 10px; family: sans-serif; }; margin: { top: 10px; left: 20px; }; padding: { bottom: 40px; right: 30px; }; }
Variables : $varWitdh : 200px
Mixins : @mixin
Ampersand(상위 선택자 참조) : &
등..
공식 사이트 : https://sass-lang.com/
테스트 사이트 : https://www.sassmeister.com/