2010-06-14 63 views
3

這裏是我的CSS爲什麼這個CSS按鈕與<a>標籤混淆?

button { 
    border: 0 none; 
    cursor: pointer; 
    padding: 0 15px 0 0; 
    text-align: center; 
    height: 30px; 
    line-height: 30px; 
    width: auto; 
} 
button a { 
    color:white; 
    text-decoration:none; 
} 

button.rounded { 
    background: transparent url(/images/button/btn_right.png) no-repeat scroll right top; 
    clear: left; 
    font-size: 0.8em; 
} 

button span { 
    display: block; 
    padding: 0 0 0 15px; 
    position: relative; 
    white-space: nowrap; 
    height: 30px; 
    line-height: 30px; 
} 

button.rounded span { 
    background: transparent url(/images/button/btn_left.png) no-repeat scroll left top; 
    color: #FFFFFF; 
} 

button.rounded:hover { 
    background-position: 100% -30px; 
} 

button.rounded:hover span { 
    background-position: 0% -30px; 
} 

button::-moz-focus-inner { 
border: none; 
} 

這裏是我的「按鈕」,在它的鏈接代碼。

<button class="rounded"><span><a href="profile.php">Profile</a></span></button> 

問題是它沒有鏈接到我點擊它時的href。 任何人都知道爲什麼?

+0

單詞配置文件在按鈕內。單擊按鈕內的任何位置都會得到相同的結果。 – 2010-06-14 20:20:53

回答

7

順便說一下,這不是一個CSS問題。這是一個「我不明白按鈕」的問題:

http://www.w3schools.com/tags/tag_button.asp

一個按鈕可以有「提交」,「按鈕」或「重啓」行動。如果您使用的是「按鈕」操作,您應該在OnClick事件中提供必要的JavaScript以導航到有問題的頁面。

0

我相信按鈕需要一個類型和值屬性。

http://www.w3schools.com/tags/tag_button.asp

您還可以添加的onclick這樣的:

<button onclick="location.href='/profile.php';">Profile</button> 

但是,因爲它只是一個普通的鏈接,你就必須使用<a>標籤,並用CSS樣式它更容易的時間。

+0

這個答案有什麼問題?這與5 + upvotes的答案几乎相同。 – Kevin 2010-06-14 20:29:34

+2

我沒有降低你的評分,但(1)答案聲稱'type'和'value'是必需的 - 它們是可選的。 (2)在聲稱它們是必需的之後,該示例沒有這些屬性! (3)它沒有解決核心問題,即按鈕內部的鏈接是無效的標記。 – 2010-06-14 21:46:15

+0

我今天在另一個問題上被釘上了一個問題,在那裏我提供了幾乎完全相同的信息,這個信息被高估了很多。看起來我犯了一個語義錯誤,稱之爲某個領域,我應該說屬性。去搞清楚。 +1提供位置的實際JavaScript代碼。 – NotMe 2010-06-14 22:33:28