concentrate on maximizing a complete table

I am facing an issue where I want to focus on a full table when it is selected, but unfortunately, clicking on the table does not trigger the focus effect.

In an attempt to work around this problem, I tested the hover effect on the table and it worked perfectly fine. How can I achieve the focus effect on the entire table?

https://jsfiddle.net/bbe7x7bp/1/

table {
    border: 1px solid #e2e2e4;
    text-align: left;
}

table:hover {
    border: 3px solid #878b93;
    outline: 1px solid #242b3a;
}

.table:focus {
    border: 1px solid blue;
    outline: 1px solid darkblue;
}

Answer №1

If you want to control the tab order of a table in your HTML, you can use the tabindex attribute. Setting tabindex="0" will place it in the natural tab order, while tabindex="-1" will make it focusable but not tabbable. Using tabindex="1" will force it to be the first item in the tab order.

Take a look at this example: https://jsfiddle.net/bbe7x7bp/2/

<table class="table" tabindex="1">
  <tbody>
  <trhead>
    <td colspan="7">Some title</td>
  </trhead>
    <tr class="table-info">
      <td>data 1</td>
      <td>data 2</td>
      <td colspan="5">data something</td>
    </tr>
  </tbody>
</table>

Additionally, you can style the table with CSS to provide visual feedback when it is focused:

table {
  border: 1px solid #e2e2e4;
  text-align: left;
}

table:hover {
  border: 3px solid #878b93;
  outline: 1px solid #242b3a;
}

.table:focus {
  border: 1px solid blue;
  outline: 1px solid darkblue;
}

For more information on the tabindex attribute, you can visit: http://www.w3schools.com/tags/att_global_tabindex.asp

Answer №2

In HTML5, elements like <a>s, <button>s, <input>s, and textareas have the :focus state by default. However, you can also assign a focus state to any element using the contenteditable and tabindex attributes. Here is an example:

<table contenteditable tabindex="1">  
  <thead>
    <tr>
      <th>Option 1</th>
    </tr>
  </thead>
  <tbody>    
    <tr>
      <td>Me</td>
    </tr>
  </tbody>
</table>

Check out the live example on Codepen here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with aligning items vertically in Bootstrap 4?

Despite my experience in programming, I am struggling with CSS and HTML. I am attempting to create a simple "Login Page" for my personal web application. GitHub: https://github.com/n-winspear/cashflow-webapp After trying various solutions suggested in ot ...

Is the top margin of the page not properly aligned?

Upon loading my page, I noticed that the bar at the top covers the header. However, by clicking the hide bar arrow, the header becomes visible. When I click the reappear arrow, the margin adjusts automatically to place the header underneath the bar. I&apo ...

Tips for avoiding Bootstrap collapse overflow within a container that has overflow-y-scroll

I'm currently facing an issue with a container that has the overflow-y-scroll CSS property. Inside this container, there's a Bootstrap collapse button that expands to show more content when clicked. The problem arises when the expanded content ov ...

Dynamic navigation menu shifting when bolded

Looking at my menu, you'll notice the following layout: If one clicks on Recruitment in the menu, it correctly bolds the text as intended. However, an issue arises where the entire menu unexpectedly shifts 1 or 2px to the left. The menu is implemente ...

Is there a way to switch up the dropdown chevron using only CSS after a click?

Is there a way to change the appearance of dropdown arrows using only CSS and animations when clicked on? I attempted the following method: body { background: #000; } #sec_opt select { /* Reset */ -webkit-appearance: none; -moz-appearance: n ...

Is there a simple way to set the form inputs to right-to-left without excessive duplication?

Is there a way to apply the right-to-left (RTL) direction to a form without duplicating code for every input, based on the locale of the language being used? Can the locale be changed in CSS to make the form RTL more efficiently? For example: <div ...

Enable wp_star_rating for display on the front end

My goal is to incorporate the wp_star_rating function into a shortcode for use on the frontend of my WordPress website. To achieve this, I have copied the code from wp-admin/includes/template.php to wp-content/themes/hemingway/functions.php. I have includ ...

I have implemented a custom-built sidebar component and I'm unsure about the process of adding data to it

After successfully incorporating this SideBar into my Vuex/Laravel project, I encountered a problem. The example code provided used: <div :class="$style.sidebar"/> However, when I tried to modify it to: <div :class="$style.sidebar">Content&l ...

CSS Layout - Float: What's floating to the top?

Are there any CSS techniques available to make floated blocks fill in both upwards and in their float direction? For example - https://i.sstatic.net/uo06B.png Instead of - https://i.sstatic.net/oEijA.png I know this can be achieved using JavaScript li ...

Ensuring form input validity in real-time using jQuery's keyup event

I've been working on a form where the user can fill in an input and press enter to move to the next field. Although I have managed to get the functionality to show the next div, I am facing issues with validation... // Moving to next div on Enter ...

Display a div in front of another using Material UI when hovering

Is there a way to display a black transparent div in front of a <MediaCard/> when hovering over it? Below is the code snippet I am using with Material UI: <Box> <Typography variant='h3'>Home Page</Typography> < ...

Preventing the element from breaking when it is not the child: Tips and Tricks

In order to align both .quote-container and #new-quote elements in the same line, even when the window width is very small (e.g., 83 pixels), I used min-width on the .quote-container element successfully. However, applying the same technique to the #new-qu ...

How can you apply margin to an element within a column in Bootstrap 4?

Within a column, I have several span elements: <div class="container-fluid"> <div class="row"> <div class="col"> <span class="myClass">some text</span> <span class="myClass">some text</span> ...

Attempting to align two distinct divisions next to each other

Here is the updated code snippet: <Grid container justify="space-between" alignItems="flex-start" direction="column" xs spacing={5} style={{ padding: 10, }}> <ParamSelection/> { state.select ...

Achieving a Full Utilization of Available Space in Bootstrap

I'm working on an app using react-bootstrap and I'm looking for guidance on how to utilize the remaining space in the main section, excluding the header and footer. Any suggestions? import Row from "react-bootstrap/Row"; import Col from ...

Experiencing difficulty adjusting the width of a Tumblr post with JavaScript or jQuery?

Calling all coding experts! I've been working on customizing a Tumblr theme, and everything is looking good except for one issue. I'm struggling to adjust the width of photos on a permalink (post) page. Check out this link: You'll notice t ...

How can I retrieve the value of a selected radio button within a fieldset using jQuery?

I have a fieldset with two radio buttons inside. When a radio button is clicked, I want to retrieve the value of the clicked button. However, my current jQuery code is not functioning correctly and I would appreciate any assistance. HTML: <fieldset id ...

Encountering blank space in the first table row after a page break when creating a PDF using dompdf

Encountered a strange bug while working with dompdf for PDF generation. The issue arises when a page break occurs within a table. Subsequent to the break, the first tr on the next page displays an odd empty space on the left side (as depicted in the image ...

center text vertically in HTML list

Here at this festival, you'll find a unique menu on the sidebar. The menu is created using an HTML list with the following structure: <ul class="nav nav-pills nav-stacked"> <li class="active"> <a href="index.html"><i ...

Centered horizontally are images that have been floated

How can I align images with different widths when they are all floated right? I want them to be aligned vertically below each other. For the best display, please view in fullscreen on your computer as the example window is small. .compressor{ height: 1 ...