我的href链接按钮无法在线使用

时间:2017-02-22 13:28:17

标签: javascript html css html5 href

我刚刚在HTML5和javascript中创建了我的第一个网站,并且所有链接都脱机工作(双重和triplechecked它),但当我将其上传到主机服务器时,没有任何链接工作。有人能给我任何建议吗?这是我的链接按钮的例子:

<div>
<center>
<button style="margin-top:10px;margin-bottom:10px;height:25px;width:100px;font-size:14px"><a href="hoverB.html">Books</a></button>
</center>
</div> 

2 个答案:

答案 0 :(得分:3)

您将锚标记放在按钮内。我假设您想要在用户点击按钮时重定向。你可以这样做:

示例1:

<a href="page.html"><button type="button">Click on me</button></a>

示例2 :(推荐)

<button type="button" onclick="location.href='page.html'">Click on me</button>

我希望这会对你有所帮助!

答案 1 :(得分:2)

否则你也可以添加带有css的锚标签,使其看起来像一个按钮

<a href="page.html" class="btn">Click on me</a>

.btn:active {
      position: relative;
    top: 1px;
    color: #fcd3a5;
    background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
    background: -moz-linear-gradient(top, #f47a20, #faa51a);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
}

.btn{
         display: inline-block;
    zoom: 1;
    vertical-align: baseline;
    margin: 0 2px;
    outline: none;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    font: 14px/100% Arial, Helvetica, sans-serif;
    padding: .5em 2em .55em;
    text-shadow: 0 1px 1px rgba(0,0,0,.3);
    -webkit-border-radius: .5em;
    -moz-border-radius: .5em;
    border-radius: .5em;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
        color: #fef4e9;
    border: solid 1px #da7c0c;
    background: #f78d1d;
    background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
    background: -moz-linear-gradient(top, #faa51a, #f47a20);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
}

JSFiddle

相关问题