-3

So I am trying to create a profile page for my website and there are multiple buttons that should link to various parts of the website. I created buttons in the following way:

<br>
<div style="text-align:center;">
    <br>
    <input class='button1' type='button' value='Profile'/>
    <input class='button1' type='button' value='My Messages'/>
    <br>
    <input class='button1' type='button' value='Create New Listing'/>
    <input class='button1' type='button' value='My Listings'/>
    <br>
    <input class='button1' type='button' value='My Bids'/>
    <input class='button1' type='button' value='My Purchases'/>
    <input class='button1' type='button' value='My Favorite Listings'/>
</body>
</html>

How can I add links to these buttons?

Maeglynx
  • 15
  • 1
  • 8
  • Does this answer your question? [How to create an HTML button that acts like a link](https://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link) – nicael Mar 30 '22 at 10:15
  • 4
    If you want a link, use [a link](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a). Apply CSS to make it look the way you want. – Quentin Mar 30 '22 at 10:15
  • You can but the whole input inside an a tag. However I would advise you to use JS to write your own click handler. – Wimanicesir Mar 30 '22 at 10:16
  • @Wimanicesir — No. `input` elements are **not allowed** inside `a` elements. – Quentin Mar 30 '22 at 10:17
  • @Wimanicesir — Using JS to write a click handler will not make it behave like a link. e.g. You can't right click and pick "open in new tab". – Quentin Mar 30 '22 at 10:18
  • @Quentin, Yes you can actually do that with JS. window.open(url, '_blank') and change the right click behaviour to open that menu. There is actually almost nothing that can't be done with JS that is done by HTML. – Wimanicesir Mar 30 '22 at 11:42
  • @Wimanicesir — That isn't what I said. A link gives the **user** the **choice** to right click and get a context menu that has that open. – Quentin Mar 30 '22 at 11:44
  • @Quentin, like I said. You can mimic the right click behaviour as well. And show the menu it would show on a link. Putting things into bold when not reading it good yourself is a bit funny :p – Wimanicesir Mar 30 '22 at 11:48
  • There are a dozen or so menu items on my link context menu. You can't replicate most of them with JS. – Quentin Mar 30 '22 at 11:52

1 Answers1

0

You're using the wrong HTML elements, which is why they won't behave the way you want.

In HTML, a link is defined using the <a href='XXX'>Link text</a> tag. If you change your input elements to a elements, you'll get them to work as you want.

The next step is then to make the link look the way you want, and you can achieve this using CSS (probably the background, color and border properties).

JohnP
  • 1,229
  • 6
  • 24