萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

十款精美 CSS 按鈕樣式:從圖標按鈕到 3D 立體效果

方案一:圖標按鈕組 (Zurb 風格)

.buttons a, .buttons button {
  display: inline-block; *display: inline; zoom: 1; /* IE7 hack */
  margin-right: 7px; padding: 5px 10px 6px 7px;
  background: #f5f5f5; border: 1px solid #ddd;
  border-top-color: #eee; border-left-color: #eee;
  font: bold 12px/130% "Lucida Grande", Tahoma, Arial, sans-serif;
  color: #565656; text-decoration: none; cursor: pointer;
}
.buttons button { padding: 4px 10px 3px 7px; } /* IE6/7 修正 */
.buttons button[type] { padding: 5px 10px 5px 7px; line-height: 17px; } /* FF/Safari */
.buttons button img, .buttons a img { margin: 0 3px -3px 0; vertical-align: middle; }

/* 狀態 */
.buttons a:hover, button:hover { background: #dff4ff; border-color: #c2e1ef; color: #336699; }
.buttons a:active { background: #6299c5; border-color: #6299c5; color: #fff; }

/* 語義色系 */
.positive { color: #529214; }
.positive:hover { background: #e6efc2; border-color: #c6d880; }
.negative { color: #d12f19; }
.negative:hover { background: #fbe3e4; border-color: #fbc2c4; }

方案二:滑動門圓角按鈕 (背景圖)

a.button {
  display: inline-block; float: left;
  background: url(bg_button_a.gif) no-repeat right top;
  padding-right: 18px; height: 24px; color: #444; text-decoration: none;
  font: 12px arial; margin-right: 6px;
}
a.button span {
  display: block; background: url(bg_button_span.gif) no-repeat left top;
  padding: 5px 0 5px 18px; line-height: 14px;
}
a.button:active { background-position: bottom right; color: #000; }
a.button:active span { background-position: bottom left; padding-top: 6px; }

左右分離圖片,適應任意文字寬度,IE6+ 完美相容。

方案三:單圖多色按鈕 (CSS Sprite)

.btn { position: relative; display: inline-block; padding: 5px; color: #fff; text-decoration: none; }
.btn * { background: url(btn2.png) no-repeat; display: block; position: relative; }
.btn i { position: absolute; left: 0; top: 0; width: 5px; height: 5px; background-position: top left; }
.btn span { padding: 0 0 5px 10px; background-position: bottom left; }
.btn span i { position: absolute; right: -10px; top: 0; width: 10px; height: 100%; background-position: bottom right; }
.btn span span { position: absolute; right: -10px; top: -5px; height: 0; background-position: top right; }
.btn.blue { background: #2ae; } .btn.green { background: #9d4; } .btn.pink { background: #e1a; }
.btn:hover { background: #a00; } .btn:active { background: #444; }

一張圖包含四個圓角,配合色塊背景色實現多主題。

現代純 CSS 3D 按鈕 (無圖片)

.btn-3d {
  display: inline-block; padding: 12px 24px;
  background: linear-gradient(#4a90d9, #3070b0);
  border: none; border-radius: 4px;
  color: #fff; font: bold 14px/1 sans-serif; text-shadow: 0 -1px 1px rgba(0,0,0,.3);
  box-shadow:
    0 1px 0 rgba(255,255,255,.2) inset,
    0 3px 0 #205080,
    0 4px 2px rgba(0,0,0,.3);
  transition: all 0.1s;
}
.btn-3d:active {
  transform: translateY(3px);
  box-shadow:
    0 1px 0 rgba(255,255,255,.2) inset,
    0 0 0 #205080,
    0 1px 1px rgba(0,0,0,.3);
}

利用 `box-shadow` 堆疊立體感,`:active` 向下位移模擬按下,零圖片、極輕量。

copyright © 萬盛學電腦網 all rights reserved