2011-09-29 159 views
0

我試圖完成這樣的事情enter image description hereCSS圖像按鈕樣式

凡按鈕都集中在頁面的中間,由50像素

這裏是我做的分離。

HTML

<div class="btn btn_tours"><a href="maps.html">Maps</a><span></span></div> 
    <div class="btn btn_maps"><a href="dbtest.html">DB Test</a><span></span></div> 
    <div class="btn btn_locations"><a href="geolocation.html">Geolocation</a><span></span></div> 
    <div class="btn btn_directions"><a href="accel.html">Accelerometer</a><span></span></div> 

CSS

.btn { 
    position: relative; 
    padding: 10px 10px 10px 10px; 
    cursor: pointer; 
    overflow: visible; 
    width:50px; 
    height: 50px; 
} 
.btn_directions{ background: url(http://tinyurl.com/5r6a3jy); no-repeat;} 
.btn_maps{ background: url(http://tinyurl.com/5r6a3jy); no-repeat; } 
.btn_tours{ background: url(http://tinyurl.com/5r6a3jy); no-repeat;} 
.btn_locations{ background: url(http://tinyurl.com/5r6a3jy); no-repeat; } 

JSFIDDLE

+0

「的

不能持有爲時已晚。」 –

回答

1

這裏簡單例子:http://jsfiddle.net/rgmCc/

+0

如何縮放按鈕內的圖像? – raym0nd

+0

您無法縮放背景圖片(僅在CSS3中支持) –

+0

您可以使用「圖片編輯器」(如Photoshop或w/e)打開圖片,並根據需要更改圖片的大小。 – Andrej

0

你的jsfiddle似乎沒有加載圖像。

將你的.btn包裝在一個div中。給它一個固定的寬度和overflow: hidden;。將其設置爲margin: 0 auto;。擺脫<center>標籤。將您的.btn設置爲float: left;

要水平居中,元素的左右側必須具有寬度和「自動」。要在div內設置網格元素,通常會將它們浮動。