1

I have a table, that I use as Nav/Side-Bar with one section of my content-container per tr and td and the section-word itself is inside an a Element. (I also used bootstrap-classes for the HTML in general)

Now the link does works on the tr/td, but not at the word itself. But I would like the link to work on the whole row as well as on the word itself. Can someone explain why that happens?

Here my code (of course with more rows in reality):

<div class="col-md-3 col-sm-3 posChild bd-sidebar justify-content-start">

          <nav id="navbar-example3"
            class="navbar sticky navbar-light flex-column justify-content-center align-items-start p-3 gy-3 sidebar d-flex"> ```
            <table>
              <table class="table">
                <thead>
                  <tr>
                    <th scope="col">Sections</th>
                  </tr>
                </thead>
              <tbody>
                <tr>
                  <td>
                    <a class="nav-link" href="#sectionID">Some Section-Word</a>
                  </td>
                </tr>
              </tbody>
            </table>
           </nav>
</div>

This is the targeted Element:

<a id="sectionID"></a>

<div>Some Section...</div>

These are the used css-classes:

.bd-sidebar {
  grid-area: sidebar;
}

.posChild {
  position: sticky;
  top: 0px;
}

.sidebar { 
 height: 100vh;
}

.navbar.sticky{
  position: sticky; top: 50px;
}
circler
  • 11
  • 2
  • I'm not sure what you're asking. Are you just wanting to have each row accept a click event that will navigate to a URL? Or are you asking how to use an anchor tag explicitly to handle navigation of a row? – Chris W. Jul 12 '22 at 13:53
  • I want the whole row, including the word inside the a-tag to accept a click-event, that navigates me to a section of the same page like an anchor link. This table (inside my sidebar) will be visible all the time whereever you scroll on the page. – circler Jul 12 '22 at 14:07
  • The anchor in the table targets the fragment identifier `#someID`, but the id on the anchor shown is `toolUsedBy`, so that's just not gonna work. The anchor shown, with class "nav-link" will work, if you change its `href` to `"#toolUsedBy"`. You can [use CSS so that it takes up the entirety of its containing table cell](https://stackoverflow.com/q/19493905/215552). – Heretic Monkey Jul 12 '22 at 14:17
  • Oh, that was a mistake, ofc the target-link in the href-attribute and the id in the targeted element are the same. Though "some section-word" isn't clickable. Other than that the table is designed as I want it to be. Sorry for the confusion. – circler Jul 12 '22 at 14:29
  • [Works here](https://jsfiddle.net/dp562ox4/) you might have CSS or something else that is making it work differently. – Heretic Monkey Jul 12 '22 at 14:35
  • Might be the case. I added the div and nav-element in which the table is nested plus the used css-classes. Do you think any of these could have an impact on my problem? – circler Jul 12 '22 at 14:54
  • @T04435 yes, this solved my problem. It works now the way I want it. Thank you very much and also thanks to the other commentators for your help! – circler Jul 12 '22 at 15:13
  • @circler Pleasure to help – T04435 Jul 13 '22 at 02:08

0 Answers0