href syntax for a button (HTML)

时间:2017-04-10 00:38:25

标签: html href

I have created a button, as shown below. Now I am working on linking it. However the href part seems to be out of order. Does anyone know how to link the button to a site (use https://aol.com). Thank you

<body>
    <div class="result15823794" style="width: 160px; height: 30px;     background-image:     url(&quot;http://static1.grsites.com/user/generate/items/button84799376.png&quot    ;);
    " onmouseover="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button76804217.png)'
    " onmouseout="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button84799376.png)'">
    <div style="background-image:     url(http://static1.grsites.com/images/0.gif); 
    width: 160px; height: 30px;"></div>
    </div>
</body>

3 个答案:

答案 0 :(得分:1)

onclick="location.href='https://aol.com/';"

Sample:

<body>
  <div onclick="location.href='https://aol.com/';" class="result15823794" style="width: 160px; height: 30px;     background-image:     url(&quot;http://static1.grsites.com/user/generate/items/button84799376.png&quot    ;);
        " onmouseover="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button76804217.png)'
        " onmouseout="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button84799376.png)'" onclick="location.href='https://aol.com/';">
    <div style="background-image:     url(http://static1.grsites.com/images/0.gif); 
        width: 160px; height: 30px;"></div>
  </div>
</body>

答案 1 :(得分:0)

you can wrap the outmost div with an anchor containing the href to AOL like this:

<a href="https://aol.com/"><div class="result15823794" style="width: 160px; height: 30px;     background-image:     url(&quot;http://static1.grsites.com/user/generate/items/button84799376.png&quot    ;);
    " onmouseover="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button76804217.png)'
    " onmouseout="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button84799376.png)'">
    <div style="background-image:     url(http://static1.grsites.com/images/0.gif); 
    width: 160px; height: 30px;"></div>
    </div></a>

答案 2 :(得分:0)

<a href="https://aol.com" target="_blank">

add this after the body the <body> tag, then add the closing of the anchor tag before the closing </body> tag. Just like my code below.

<body>
    <a href="https://aol.com" target="_blank">
    <div class="result15823794" style="width: 160px; height: 30px;     background-image:     url(&quot;http://static1.grsites.com/user/generate/items/button84799376.png&quot    ;);
    " onmouseover="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button76804217.png)'
    " onmouseout="this.style.backgroundImage =     'url(http://static1.grsites.com/user/generate/items/button84799376.png)'">
    <div style="background-image:     url(http://static1.grsites.com/images/0.gif); 
    width: 160px; height: 30px;"></div>
    </div>
    </a>
</body>