Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6328149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:24:26+00:00 2026-05-24T17:24:26+00:00

This question is about keyboard focus for various kinds of links. Link inside div

  • 0

This question is about keyboard focus for various kinds of links.

Link inside div – a simple link like below can be accessed by keyboard tabindex, but there’s a gap between the div and the link so the mouse can hover over the div without setting off the link’s :hover event.

<div class="greenButton">
  <%= link_to "Back", :back %>
</div>

Div inside link – the code below keeps :hover events together (and in general the styled link behaves how I would expect) but the keyboard doesn’t get to it through tabindex.

<%= link_to :back do %>
  <div class="greenButton">Back</div>
<% end %>

How can I get both the better formatting of the bottom situation with a tabindex?

Note: the manual tabindex declaration is not a good option because this is code that will be used for multiple pages where there are different numbers of elements. Is there a Rails-y way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:24:27+00:00Added an answer on May 24, 2026 at 5:24 pm

    Generally, block-level elements may contain inline elements and other
    block-level elements. Generally, inline elements may contain only data
    and other inline elements. Inherent in this structural distinction is
    the idea that block elements create “larger” structures than inline
    elements.

    Source

    In other words: you shouldn’t put a block element like div inside an inline element like a. I recommend losing the div and just style the a element:

    <%= link_to "Back", :back, :class => 'greenButton' %>
    

    If this isn’t feasible, you could try replacing the div with a span and see if the tabindex gets picked up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question about different testing frameworks yesterday. This question can be found
This question about Timers for windows services got me thinking: Say I have (and
Followed this question about delayed_job and monit Its working on my development machine. But
I have seen this question about deploying to WebSphere using the WAS ant tasks.
Follow up to this question about GNU make : I've got a directory, flac
This is sort of the Java analogue of this question about C# . Suppose
JD Long helped me with this: question about manual annotation . But is it
A few days ago I asked this question about jquery ajax function invoking action
This question is about programming small microcontrollers without an OS. In particular, I'm interested
This question is about a data structure I thought of. It is a dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.