選擇器 {
屬性: 值;
}
div {
width: 200px;
height: 200px;
}
元素類型(重要!!)
div {
display: block;
}
元素定位(重要!!)
div {
position: relative;
}
top、bottom、left、right
div {
position: absolute;
bottom: 0;
top: 0;
left: 0;
right: 0;
}
浮動(重要!!)
div {
float: right;
}
.content {
float: left;
}
寬, 高
div {
width: 200px;
height: 200px;
}
最大尺寸, 最小尺寸
div {
width: 200px;
height: 200px;
max-width: 100px;
max-height: 100px;
min-width: 50px;
min-height: 50px;
}
背景
<!-- 完整寫法 -->
div {
background: #ffffff url("img_tree.png") no-repeat right top;
}
分開寫
div {
background-color: #ffffff;
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
文字字型
div {
font-family: "Times New Roman", Times, serif;
}
字體粗細
div {
font-wight: bold;
}
顏色
div {
color: #ccc;
}
行高
div {
line-height: 1em;
}
文字對齊
div {
text-align: center;
}
文字裝飾
.a-link {
text-decoration: underline;
}
文字陰影(CSS3)(支援度)
.a-link {
text-shadow: 2px 2px 4px #ff0000;
}
邊框
div {
border: 1px solid #ccc;
}
.content {
border-width: 1px;
border-style: solid;
border-color: #ccc;
}
.content-2 {
border-left: 1px solid #ccc;
}
圓角(CSS3)(支援度)
div {
border-radius: 25px;
border-radius: 25px 25px 25px 25px;
}
方向口訣: 左上、右上、右下、左下
內距
div {
padding: 2px;
}
.content {
padding-left: 2px;
padding-right: 2px;
padding-top: 2px;
padding-bottom: 2px;
padding: 2px 2px 2px 2px;
}
方向口訣: 上、右、下、左
外距
div {
margin: 2px;
}
.content {
margin-left: 2px;
margin-right: 2px;
margin-top: 2px;
margin-bottom: 2px;
margin: 2px 2px 2px 2px;
}
方向口訣: 上、右、下、左
模型寬高基準
div {
box-sizing: content-box;
box-sizing: border-box;
}
1. 由 W3C 完成標準制定。
2. 取代 HTML 4.01 和 XHTML 1.0
3. 廣義包刮 CSS 及 Javascript
4. 新增很多語法(video、canvas)
5. 刪除不必要的標籤(font、center)
HTML5 仍然在持續的不斷修正中。
1 .Youtube 提供 HTML5 播放器
2. 賈伯斯宣布放棄 Flash 相關的支援
.box {
li {
p { ... }
h1 { .... }
.content { ... }
a {
span { ... }
}
}
}
更簡單的 SCSS
$primaryColor: #eeccff
body
$primaryColor: #ccc
background: $primaryColor
p
color: $primaryColor
a
font-size: 18px
最適合初學者
$primaryColor: #eeccff;
body {
$primaryColor: #ccc;
background: $primaryColor;
}
p {
color: $primaryColor;
a {
font-size: 18px;
}
}
也不賴啦~
@font-color: #ccc;
div{
span {
font-size:20px;
color: @font-color;
b {
color:red;
}
}
i {
font-size:12px;
}
}
Before:
$text-size:18px;
body{
font-size:$text-size;
}
#content{
width:$text-size;
}
After:
body {
font-size: 18px;
}
#content {
width: 18px;
}
Before:
$width:200px;
.content {
width: $width;
height: $width*2;
font-size: $width/10;
}
After:
.content {
width: 200px;
height: 400px;
font-size: 20px;
}
Before:
@mixin border-radius($angle){
border-radius:$angle;
-webkit-border-radius:$angle;
-moz-border-radius:$angle;
}
#box{
@include border-radius(10px);
}
After:
#box {
border-radius: 10px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
}
Before:
.ext{
font-size:10px;
width:400px;
}
body{
@extend .ext;
height:600px;
}
After:
.ext, body {
font-size: 10px;
width: 400px;
}
body {
height: 600px;
}
table {
margin: 2em 0;
tr{
margin: 5px;
}
td {
text-align: right;
}
}
.content {
width: 20px;
height: 10px;
.content-title {
font-size: 18px;
}
}
// 編譯後
table {
margin: 2em 0;
}
table tr {
margin: 5px;
}
table td {
text-align: right;
}
.content {
width: 20px;
height: 10px;
}
.content .content-title {
font-size: 18px;
}
$yDark: darken(#FEDD31,50%);
$color_1: rgba(#102030, 0.5);
$color_2: lighten(#800, 20%);
a {
color: $yDark;
}
// 這是佔著茅坑不拉屎
.all-list-default-style-2 {
display: inline-block;
width: 100px;
height: auto;
}
.list-c {
@extend .all-list-default-style-2;
color: red;
}
.list-d {
@extend .all-list-default-style-2;
color: blue;
}
// %
%all-list-default-style {
display: inline-block;
width: 100px;
height: auto;
}
.list-a {
@extend %all-list-default-style;
color: red;
}
.list-b {
@extend %all-list-default-style;
color: blue;
}
不是新技術,只是設計模式,或者可以說是一種規範,主要可分為:
css 選擇器: .main-menu ul li a { .... }
css 選擇器: .main-menu a { .... }
css 選擇器: .main-menu-link { .... }
.default-button {
display: inline-block;
padding: 8px 18px;
color: #fff;
border-radius: 4px;
&.button-default { background: hsla(30, 10%, 40%, 1); }
&.button-primary { background: hsla(360, 6%, 70%, 1); }
}
按鈕1
按鈕2
下載完成,解壓縮後進入資料夾,可看到應用程式(Fire.app),點選開啟,可以右下角看到應用程式圖示。
點選icon後出現選單,選擇"Watch a Folder...",選擇你的專案,完成專案選取。
點選設定的"Change option",設定 sass 原始檔案及編譯後的 css 存放位置。
ERB 樣板生成 HTML