香港網頁網設計 Web Design Hong Kong Blog
香港網頁設計Blog - 分享網頁設計的樂趣, 技巧和心得
RSS RSS 訂閱
http://blogsessive.com/wp-content/uploads/2008/10/feedburner-logo.png Email 訂閱
  • 首頁
  • 關於我們
  • 有問有答討論區
  • 文章列表
  • Archive
  • 網頁設計
  • 聯絡我們
首頁 » User Interface Design

簡易CSS圓角教學

2009年05月26日 2,061 views 目前有1個回應

1. 簡易CSS圓角

彈性圓角邊框的傳統製作方式是利用 table 的 4 個角落各放一張圓角小圖, 再利用背景圖做上下左右 4 邊線條的伸縮效果, 在想避免使用 table 排版, 精簡原始碼的人眼中, 這種方式很多餘, 但又ㄧ直沒有更好的替代方式.

“101個您一定會遇到的問題與解答” 書中曾介紹 3 種製作彈性圓角的方式…

, 但都不十分理想:

第一種方式是用Firefox專用語法 –moz-border-radius 設定圓角邊框, 只有在 Firefox 瀏覽器可以看見圓角效果, IE 無效.

第二種方式是利用很多僅 1px 邊界設定差異的 <div> 包覆內容, 書中範例在內文上方用 9 個 <div>, 下方也用 9 個 <div> 才完成一個圓角邊框設定, 步驟繁複不說, 顯示的鋸齒效果也不太好.

第三種方式是先切好 4 張小圓角圖, 二張放 html 上, 二張放 css 背景裡面, 再用 class 設定圓角與邊線位置, 這不純是用 css 作成的, 比較像是傳統 table 方式的變身. 對還需要放 2 張圖在 html 上的做法不是很欣賞.

有ㄧ篇 Simple Rounded Corner CSS Boxes 是目前看起來最好的用法, 只用 4 個 class 和一張背景圖就完成圓角邊框設定, 而這張背景圖也允許有立體陰影等效果. 原文是做固定寬度 335px , 這邊我改為彈性寬度, 所以將 width: 335px 刪除, 也對內文與標題間距做點調整.

首 先要設計一張夠大的圓角框背景圖 (寬 3200px, 應該沒有比這更寬的螢幕了, 高度也視需求製作), 如果要有陰影立體也直接畫好, 圖雖然大張, 但色階不多的話, 存成 jpg 或 png 也只有幾十 K 大小, 不必擔心檔案過大. 如果標題很長或可能有好幾行字, 可將標題區域高度做大一些, 讓文字有向下伸展空間. 然後再用 4 個 class 對同一張圖做標題及上下左右圓角顯示位置和間距的設定. 這方式不管是html或css設定都很簡潔, 效果可視需求做多元的變化.

Html範例如下:

<div class=”cssbox”>
<div class=”cssbox_head”><h2>This is a header</h2></div>
<div class=”cssbox_body”>
<p>This is for your content. … This is for your content.</p>
</div>
</div>

CSS設定如下:

/* 設定右下角圓角圖 */
.cssbox, .cssbox_body, .cssbox_head, .cssbox_head h2 {
background: transparent url(box.jpg) no-repeat bottom right;
}

/* 可固定寬度值 (例如 width: 335px;) 或刪除寬度改為隨內容伸展的彈性寬度 */
.cssbox {
padding-right: 15px;
/* 底圖右邊緣間距 */
margin: 20px auto; /* 地圖上下左右邊界 */
}

/* 設定右上角圓角圖 */
.cssbox_head {
background-position: top right;
margin-right: -15px; /* 右上角底圖向上拉高 15px */
padding-right: 40px; /* 右邊間距 = 圖片間隙 + 內側間距 */
}

/* 設定左上角圓角圖 */
.cssbox_head h2 {
font-size: 120%;
background-position: top left;
margin: 0;
/* 邊界設定為 0*/
border: 0; /* 框線設定為 0 */
padding: 5px 0 5px 40px; /* 左側間距 = 圖片間隙 + 內側間距 */
height: auto !important;
height: 1%;
/* IE Holly Hack 修正 */
}

/* 設定左下角圓角圖 */
.cssbox_body {
background-position: bottom left;
margin-right: 25px;
/* 右邊間距 */
padding: 15px 0 15px 40px; /* 間距設定, 左側 40px 要與 .cssbox_head 相同 */
}
/* 內文與標題間距修改 */
.cssbox_body p {
margin-top: 0 ;
}

這 是利用 cssbox 和 cssbox_body 做右下和左下圓角, .cssbox_head 和 .cssbox_head h2 做右上和左上圓角, 並針同一張圖的背景 (background-position) 做置左置右或靠上靠下設定. 所以 4 邊的 margin 和 padding 必需互相對稱搭配, 才能做出無縫隙, 上下左右均衡的圓角邊框.

好用的 “CSS彈性圓角邊框設定” 推薦給各位!

2. 產生圓角圖形

RoundedCornr 是一個能幫助使用者,經過幾步簡單的設定後就可以產生圓角圖形或是含有圓角邊框的內容盒 (rounded corner box) 的網站。

圓角一直是很多網站喜歡使用的設計元素之一,尤其近來所謂的 Web 2.0 網站越來越多,其中許多網站就採用了大量的圓角做為版面的設置,就像 Web 2.0 網站的 logo 通常都有倒影一樣。

RoundedCornr 可以產生以下幾種的圓角:

  1. Basic RoundedCornr: 單色的圓角背景
  2. RoundedCornr with Gradient: 漸層色的圓角背景
  3. RoundedCornr with Border: 含有圓角邊框的內容盒
  4. Single RoundedCornr Image: 單純的圓角圖案,例如按鈕。可在圖案上面打文字。

圓角產生完畢之後,RoundedCornr 會秀出 HTML 及 CSS 原始碼,還有圖案的連結,只要將圖案下載到自己的電腦,然後將原始碼貼到網頁編輯器就可以開始動手打造有圓角的網頁了。

網站:http://www.roundedcornr.com/

Related posts:

  1. Finding freelance web design
  2. 我想索取網站設計的報價, 需要提供甚麼資料?
  3. Website-Freelance.com professional website design
  4. 塗鴉風格網頁layout規畫工具:Balsamiq Mockups

One Comment »

  • rain said:

    Web design–網頁設計is the skill of designing presentations of content that is delivered to an end-user through the World Wide Web, by way of a Web browser or other Web-enabled software like Internet television clients, microblogging…

    # 23 七月 2009 at 3:46 下午

我要留言!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.

最多觀看文章

  • 2000 個高質素網頁模板免費下載 (Free web design templ... - 11,885 views
  • 2500個最受歡迎網頁設計資源 (Top 2500 Best Design Re... - 6,200 views
  • 5個免費網頁寄存空間 - 5,558 views
  • 10 個精選網頁素材網站 - 4,664 views
  • 免費網站空間 (Free web hosting HK) - 4,608 views

文章分類

  • Internet Marketing (8)
    • SEO (7)
  • Uncategorized (43)
  • Web Design Articles (6)
  • Web Trend (2)
  • Website Freelance (38)
  • WordPress (3)
  • 免費CSS網頁模板 (1)
  • 圖像設計 (1)
  • 精選文章 (5)
  • 網絡新聞 (6)
  • 網頁寄存 (2)
  • 網頁教學 (1)
  • 網頁設計 (15)
    • User Interface Design (5)
    • 圖像設計 (2)
    • 網站推介 (8)
    • 網頁設計 Tips (2)
  • 網頁資源 (12)
    • 免費CSS網頁模板 (1)
    • 圖示 (2)
    • 桌布 (Wallpaper) (2)
    • 網頁寄存 (1)
    • 網頁模板 (4)
    • 網頁素材 (4)
  • 頭條文章 (1)

標籤

best cms css design designer download flash free Freelance Freelance Job Freelance Programmer Freelancer freelance web design google high hk hong kong hosting icon logo mysql optimization php popular programmer quality quotation resources search SEO template templates tools tutorial Uncategorized web web design HK Web Design Hong Kong website WordPress yahoo 免費 網頁 網頁模板 網頁設計

Blogroll

  • Development Blog
  • Documentation
  • Plugins
  • Suggest Ideas
  • Support Forum
  • Themes
  • WordPress Planet

其它

  • 註冊
  • 登入
  • 文章 RSS 訂閱
  • 迴響 RSS 訂閱
  • WordPress.org
香港網頁設計Blog
- 分享網頁設計的樂趣, 技巧和心得

最新迴響

  • A Freelance programmer
  • 網頁設計
  • 2000 個高質素網頁模板免費下載 (Free web design templates)
  • 關於我們
  • [香港 Hong Kong] Freelance Web Designers, Programmers, Writers. Custom Web Design, website

熱門文章

  • 2000 個高質素網頁模板免費下載 (Free web design templates) - 11,885 views
  • 2500個最受歡迎網頁設計資源 (Top 2500 Best Design Resources of 2009) - 6,200 views
  • 5個免費網頁寄存空間 - 5,558 views
  • 10 個精選網頁素材網站 - 4,664 views
  • 免費網站空間 (Free web hosting HK) - 4,608 views
Powered by WordPress | 登入 | Entries (RSS) | Comments (RSS) | Arthemia theme by Michael Hutagalung