-1

I have a table of six columns. The table is formatted with odd and even row colours with current row highlighted with different colour. I am using this table to list pdf documents which can be viewed depending on which row is clicked. All this works smoothly.

The problem I have is that I really don't want to have to tell users to double click a row. The idea is that every row has one cell (the 4th column as it happens) containing the text 'View'. What I want to do is to hide this text by setting it to the same colour of the (alternating) background colour and bringing in line with the other cells in the row when hovering on that row. My current css code is:

.tableid .row-hover tr:hover td {
    background-color: #b3f0ff;
    color: #000000;
}

.tableid .odd td {
    background-color: #DFF2FE;
    color: #000000;
}

.tableid .even td {
    background-color: #F2FAFF;
    color: #000000;
}

.tableid .selected tr {
    background-color: #FF0000;
    color: #FFFFFF;
}

Have tried multiple variations of cell selection including child selectors but so far have fallen at every hurdle. Don't know if I'm missing something fundamental or simple so apologies if I have missed the obvious.

ps: Don't know if this is relevant but the table is in the WordPress environment.

2
  • 3
    "I have a table of six columns." - please share that HTML (I'm aware that it's composed in, and possibly via, Wordpress but please show the HTML that the browser receives, not the server-side PHP that generates it). Also, your question is vague: you want to hide the "view" text when the user hovers, or when not hovering? Is that text wrapped in another element (hence why we'd need to see the HTML)? Should it be click-able, or not? Focus-able, or not? Is the user supposed to click, double-click, or just not click? What should they click, or not click? Please see "How to Ask" and "minimal reproducible example." Commented Sep 16, 2023 at 13:17
  • 1
    Apologies, this was my first post to Stack Overflow. I would have provided the information you requested but @Lars has kindly already provided a good example of my problem and this has created a solution. Commented Sep 16, 2023 at 17:26

2 Answers 2

1

Thanks Lars for your answer. It wasn't quite what I was wanting but your idea solved my problem. To help others - I resolved my problem by replacing the following code in your example with:

     .tableid .row-hover tr:hover td:nth-child(4) {
     color: transparent;
     }

with:

     .tableid tr td:nth-child(4) {
     color: transparent;
     }

This code highlights the 'award' when the row is selected by hover.

Sign up to request clarification or add additional context in comments.

Comments

0

Your goal is a bit vague, though from what I understood is that you're trying to make the text invisible. You've figured setting the text to be the same as the background color could achieve that.

I would sugest to set the background color to transparent instead. It seems easier to do, you would not have to worry about the 'even/odd' color scheme.

/* New css rules */
/* Instead of making the text the same colour, 
   set it to transparent 
   The 4-th cell contains the 'view' text, we're selecting that one with the 
   ':nth-child' selector
*/
.tableid .row-hover tr:hover td:nth-child(4) {
  color: transparent;
}

/* Make clear to the user this can be clicked by changing the mouse to pointer */
.tableid .row-hover tr {
  cursor: pointer;
}

/* Your existing css */

.tableid .row-hover tr:hover td {
  background-color: #b3f0ff;
  color: #000000;
}

.tableid .odd td {
  background-color: #DFF2FE;
  color: #000000;
}

.tableid .even td {
  background-color: #F2FAFF;
  color: #000000;
}

.tableid .selected tr {
  background-color: #FF0000;
  color: #FFFFFF;
}
<table class="tableid">
  <thead>
    <tr>
      <th>Company</th>
      <th>Contact</th>
      <th>Country</th>
    </tr>
  </thead>
  <tbody class="row-hover">
    <tr class="odd">
      <td>Alfreds Futterkiste</td>
      <td>Maria Anders</td>
      <td>Germany</td>
      <td>view</td>
    </tr>
    <tr class="even">
      <td>Centro comercial Moctezuma</td>
      <td>Francisco Chang</td>
      <td>Mexico</td>
      <td>view</td>
    </tr>
    <tr class="odd">
      <td>Ericworks</td>
      <td>Eric everhead</td>
      <td>Botswana</td>
      <td>view</td>
    </tr>
    <tr class="even">
      <td>Slingshot productions</td>
      <td>George Garbanzo</td>
      <td>Sweden</td>
      <td>view</td>
    </tr>
  </tbody>
</table>

3 Comments

Thanks Lars for your answer. It wasn't quite what I was wanting but your idea solved my problem.
Apologies @Lars - still finding my way round Stack Overflow
No worries, Asking questions here can be daunting. People want to help you though. Things that seem obvious to frequent users, might not be so obvious to fresh account. I'm happy you managed to solve it by adapting the example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.