Home > Enterprise >  Can't link text in <span> tag
Can't link text in <span> tag

Time:01-30

I have a template with a navigation made of span elements. I want to add a URL to one of the span elements that it opens a certain URL in a new tab. What am I doing wrong? (I'm a beginner in programming)

<Tab>
  <img className="svg" src="/assets/img/svg/briefcase.svg" alt="briefcase" />
  <span href="url.html" className="menu_content">eindrücke</span>
</Tab>

CodePudding user response:

Spans are used to display text.

If you want to add a link you need to add an anchor element <a>.

You need to write:

<a href='YOUR_LINK'>text_of_your_link</a>

Instead of :

<span>your_text</span>

You can use <a> to link to other urls or to ids in your HTML.

If you want to link to an id in the same page you write:

<a href='#YOUR_ID'>your_text</a>

The page will then scroll to the that id in your page.

If you want a link to go to a page and directly scroll to an id, your write:

<a href='https://yourlinkurl.com/#THE_ID'>your_text</a>

If you want to add navigation inside of your react app, and add different URLs to the pages of your React app, you will need to add a library (like React Router).

In that library, you have custom components that you will use to navigate inside your app. They are used like this:

<Link to='/your_local_url'>your_text</Link>

https://reactrouter.com

  •  Tags:  
  • Related