How to create an HTML button that acts like a link?

后端 未结 30 3554
长发绾君心
长发绾君心 2020-11-21 04:18

I would like to create an HTML button that acts like a link. So, when you click the button, it redirects to a page. I would like it to be as accessible as possible.

30条回答
  •  有刺的猬
    2020-11-21 05:19

    People who have answered using attributes on a was helpful.

    BUT then recently, I encountered a problem when I used a link inside a

    .

    The button is now regarded like/as a submit button (HTML5). I've tried working a way around, and have found this method.

    Create a CSS style button like the one below:

    .btn-style{
        border : solid 1px #0088cc;
        border-radius : 6px;
        moz-border-radius : 6px;
        -webkit-box-shadow : 0px 0px 2px rgba(0,0,0,1.0);
        -moz-box-shadow : 0px 0px 2px rgba(0,0,0,1.0);
        box-shadow : 0px 0px 2px rgba(0,0,0,1.0);
        font-size : 18px;
        color : #696869;
        padding : 1px 17px;
        background : #eeeeee;
        background : -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(49%,#eeeeee), color-stop(72%,#cccccc), color-stop(100%,#eeeeee));
        background : -moz-linear-gradient(top, #eeeeee 0%, #eeeeee 49%, #cccccc 72%, #eeeeee 100%);
        background : -webkit-linear-gradient(top, #eeeeee 0%, #eeeeee 49%, #cccccc 72%, #eeeeee 100%);
        background : -o-linear-gradient(top, #eeeeee 0%, #eeeeee 49%, #cccccc 72%, #eeeeee 100%);
        background : -ms-linear-gradient(top, #eeeeee 0%, #eeeeee 49%, #cccccc 72%, #eeeeee 100%);
        background : linear-gradient(top, #eeeeee 0%, #eeeeee 49%, #cccccc 72%, #eeeeee 100%);
        filter : progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#eeeeee',GradientType=0 );
    
    }
    

    Or create a new one here : CSS Button Generator

    And then create your link with a class tag named after the CSS style you have made:

    Link
    

    Here's a fiddle:

    JS Fiddle

提交回复
热议问题