2017-02-01 38 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/