最近在使用 jQuery UI Dialog 這個插件,功能確實很強大,不過樣式設定相對麻煩一些。折騰了兩天,總算摸清楚了其中的門道,這裡記錄一下心得。
先來看看執行插件所需的環境:
<script src="../../JS/jquery-1.4.2.js" type="text/javascript"></script>
<script src="../JS/jquery.ui.js" type="text/javascript"></script>
<link href="CSS/themes/redmond/jquery.ui.all.css" rel="stylesheet" type="text/css" />
其中 jquery.ui.all.css 是啟動樣式用的 CSS。用 Firefox 打開檢視,浮層標題的結構如下:
<span id="ui-dialog-title-divShow" class="ui-dialog-title" unselectable="on" style="-moz-user-select: none;">百姓一站通提示</span>
其實就是一個 span。掌握這個 class「ui-dialog-title」後,我們就能到官網的 CSS 目錄裡找到 jquery.ui.dialog.css 檔案,搜尋 ui-dialog-title 這個樣式:
.ui-dialog .ui-dialog-title { font: 62.5% "Trebuchet MS" , sans-serif;font-weight:bold;float: left; margin: .1em 16px .1em 0; height:15px }
只要針對這段 CSS 做修改,就能達到我們想要的浮層標題樣式。
原本的樣式帶有背景圖片:
.ui-widget-header { border: 1px solid #aaaaaa; background: #cccccc url(images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x; color: #222222; font-weight: bold; }
若想改用純色背景,可以把背景圖片拿掉,改成背景顏色:
.ui-widget-header { border: 1px solid #aaaaaa; background-color:red; color: #222222; font-weight: bold; }
關閉按鈕等圖示的樣式定義在:
.ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png); }