2017-02-01 78 views
3

我剛開始編程,我想用html嘗試CSS。然而,我仍然遇到像我想要一個按鈕這樣的錯誤,但是當顯示在瀏覽器上時,所述按鈕變成鏈接。 有人可以解釋嗎?使用一個帶有鏈接的div的導航按鈕

<!DOCTYPE html> 

<html> 
    <head> 
     <meta charset="utf-8"> 
     <title>Linking External Style Sheets</title> 

    <style> 
     h1 { 
     color: blue; 
     } 
     a { 
     color: blue; 
     text-decoration: none; 
     } 
     a:hover { 
     background-color: yellow; 
     } 
    </style> 
    </head> 
    <body> 
     <div><p><em>Click here:</em> 
     <a class="w3-btn" href="http://www.w3schools.com">Link Button</a> 
     </div> 
    </body> 
</html> 

我想給它一個邊框,背景和文本顏色也,使之改變時,在它的代碼那裏有一個鼠標...

回答

2

如果你想有一個按鈕,然後簡單地使用<button>代替<a>

<button class="w3-btn" href="http://www.w3schools.com">Link Button</button>

然而,由於按鈕適合的形式則不能使用HREF的一個按鈕。在這種情況下,您可以將鏈接樣式設置爲按鈕(@RahulB答案),或者將表格提交至http://www.w3schools.com

<form action="http://www.w3schools.com" method="POST"> 
     <button class="w3-btn" type="submit>Link Button</button> 
</form> 
+0

在一個單獨的話題,這是怎麼做到的外部樣式表 –

+0

放置一個css文件裏面你的風格,然後將文件導入到你的HTML與'<鏈接相對=「樣式的」 href =「stylefile.css 「>'。將此代碼放置在html代碼的''部分。 –

1

可以樣式的鏈接作爲按鈕 -

a{ 
     color: blue; 
     text-decoration: none; 
     border : 1px solid black; 
     padding : 10px; 
     background-color : cyan; 
     border-radius: 10px; 
     appearance : button; 
     } 

小提琴鏈接:https://jsfiddle.net/vgwgsoqt/1/