in Education by
When assigning a background color of a table cell on hover, the box shadow is covered. I have found several questions asking something similar, and my understanding is this is correct behavior: background colors do overlay box shadows. However, I have seen several answers on here using a "mask" (new element) or :before and :after. The "mask" solution won't work for me as I cannot edit the HTML. I first tried using borders instead of box shadows, but that moved the rows up and down due to varying heights. Is this possible? Row should highlight on hover, cell should highlight a different color on hover, row should have 4px border on hover but cells should not shift up/down on hover. table { border-collapse: collapse; } table tr:hover { box-shadow: inset 0px 0px 0px 4px blue; background: red; } table tr td { border: 1px solid black; padding: 5px; } table tr td:hover { background: yellow; } table tr td:hover::before { content: ''; display: block; box-shadow: inset 0 0 0 4px blue; position: relative; top: -5px; height: 4px; } table tr td:hover::after { content: ''; display: block; box-shadow: inset 0 0 0 4px blue; position: relative; bottom: -5px; height: 4px; }
AAA BBB CCC DDD
AAA BBB CCC DDD
AAA BBB CCC DDD
Run code snippetExpand snippet JS Fiddle: https://jsfiddle.net/jennifergoncalves/guqtj4y0/26/ JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You didn't specify how you want to accomplish the borders. In your title you box-shadow, but in your description you try to do it with borders: Row should highlight on hover, cell should highlight a different color on hover, row should have 4px border on hover but cells should not shift up/down on hover. I didn't do it with an actual border. Instead, I set an outline and just set an outline-offset. This should be what you're looking for. Show code snippet This solution is very convenient because you can pretty easily style an outline. If you, for example, want to add an outline to the specific table cell that is hovered, just add the outline to the cell with the according pseudo-class and you should be ready to go.

Related questions

0 votes
    When assigning a background color of a table cell on hover, the box shadow is covered. I have found ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    So I'm using Supersized to scale my background images and that's all good and well. The problem ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I have a list, and each item is linked, is there a way I can alternate the background colors for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 9, 2022 in Education by JackTerrance
0 votes
    I have a list, and each item is linked, is there a way I can alternate the background colors for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    I have a list, and each item is linked, is there a way I can alternate the background colors for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 8, 2022 in Education by JackTerrance
0 votes
    I have a list, and each item is linked, is there a way I can alternate the background colors for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    I have a search box. The box itself is an image and the button is an image too. The CSS is as ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I'm working on this project and I required to allow the user to select a color from the color ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    Which HTML5 tag would you use to define footer?...
asked Apr 10, 2021 in Education by JackTerrance
0 votes
    I want to display the label of an input inside its input, so that when I click the input, the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    Semantically speaking, is there an appropriate place in today's websites (late 2008+) where using the bold ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    The ___________ class adds a rounded border around an element with a gray background color and some padding. ... .alert .jumbotron Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Is is possible to change the item selection focus color and text color in a TListBox? When themes are ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    I have created floating label in input field.In chrome view is working fine, but not properly viewed in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to remove the space between inline/inline-block elements? (41 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...