Using `position:relative` causes the border to be concealed in Internet Explorer

I am experiencing an issue with a table where the top row has a position:relative attribute. In Internet Explorer 9, adding this attribute causes the border between the cells to disappear (this does not happen in Chrome).

Although my question is similar to this one, I cannot set the z-index of the top row lower than the other rows because it will be a fixed header requiring a higher z-index.

Below is the HTML code:

<table border="1">
            <tr >
                <td class="locked">header 1</td>
                <td class="locked">header 2</td>
            </tr>
            <tr >
                <td>data 1a</td>
                <td>data 1b</td>
            </tr>
            <tr >
                <td>data 2a</td>
                <td>data 2b</td>
            </tr>
        </table>

CSS code:

.locked {
            position: relative;
            background-color: Yellow;
        }

If anyone knows how to resolve this issue and display the border while keeping the z-index greater than other cells, please advise.

Edit: Here is a jQuery code snippet that explains why the header position is relative:
1. It allows the header to scroll horizontally and vertically.
2. The header remains at the top of the screen when scrolling down more than 153 pixels.

$(document).ready(function () {
    $(window).scroll(function(){ 
        var off = $(window).scrollTop();
        if (off < 153) {
            $(".frozenTop").css("top", 0);
        } else {
            $(".frozenTop").css("top", off - 153);
        }
    });
});

Answer №1

To enhance the appearance of elements in browsers that support CSS3, using the CSS3 property background-clip can be beneficial:

.locked {
    position: relative;
    background-color: Yellow;
    background-clip: padding-box;
}

For more information on this property, visit:https://developer.mozilla.org/en-US/docs/CSS/background-clip

Answer №2

Give this a Try, it Could be Helpful

<td class="locked"><div>heading 1</div></td>
<td class="locked"><div>heading 2</div></td>

table {
border-spacing: 0px;
}
.locked {
position: relative;
border:none;
}
.locked div{
border:2px black solid;
background-color: Yellow;
margin:-2px;
}

Check it out on jsFiddle

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

What is the best way to display photos horizontally instead of vertically on a webpage?

Is there a way to display these photos (found at ) in a row instead of a column? Can someone provide instructions on how to achieve this? Additionally, should I use one div for all the images or create a separate div for each image? Furthermore, it would ...

Creating a unique Bootstrap 4 custom checkbox design without the use of the "for" attribute on the label

Are there alternative methods for maintaining the Bootstrap 4 custom checkbox design without utilizing the input's ID and label's 'for' attribute? The styling for when the box is checked disappears if these are removed. For instance: ...

Material-UI: The Mystery of Missing CSS Properties

Struggling to apply a CSS class to an element from Material-UI: bw:hover { -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */ filter: grayscale(100%); } Tried using makeStyles: import { makeStyles } from '@material-ui/core/styles' ...

How to Style an Element Based on Fragment Identifier in Href Attribute Using CSS

I've implemented the tabview feature from the YUI3 library. This is how the markup code appears: <div id="demo" class="yui3-tabview-content"> <ul class="yui3-tabview-list"> <li class="yui3-tab yui3-widget yui3-tab-selected"> ...

What are the steps for troubleshooting LESS in Chrome?

It appears that the art of LESS debugging has made significant progress in the last year, and I am curious to know how many people have experience using developer tools in Chrome/Canary for debugging. My goal is to make sure that when I debug a file, the ...

The W3C Validator has found a discrepancy in the index.html file, specifically at the app-root location

While attempting to validate my HTML page, I encountered the following error: Error: Element app-root not allowed as child of element body in this context. (Suppressing further errors from this subtree.) From line 4347, column 7; to line 4347, column 16 ...

Struggling to repair the unresponsive on-click event even after thorough debugging efforts

i am working on a project where i have to create a datatable, but I am facing an issue with the edit event not firing on click. Even after debugging, it is not pointing towards any error. function GetLoginData() { $.ajax({ url: '/LoginMas ...

Ways to enhance widget titles with borders on Blogger

As a Blogger user, I am looking for guidance on how to add a border around the title of each widget/gadget. When I place widgets such as About Me, Follow Us, etc., in my sidebar, I want them to have borders like in this image. While I know how to customize ...

Efficient jQuery Algorithm for Calculating Image Viewport Sizes Without Scrollbars

I am trying to create an image hover effect, but I am encountering an issue. When I hover over certain images, unwanted scrollbars appear, and I would like to find a way to prevent this from happening. It seems to be related to the viewport and calculation ...

Displaying a Bootstrap button and an input box next to each other

Looking for advice on aligning or arranging a button and input box side by side in Bootstrap without grouping. I've searched online for examples, but they all involve grouping of elements. jsfiddle: https://jsfiddle.net/erama035/p9dagmL3/3/ <div ...

Only half of the image is responsive to hover effects

Just starting out with coding and running into an issue... My social media icons are supposed to turn pink on hover using a second image, but for some reason it's only showing up on the bottom half. Any suggestions? CSS: a.twitter:hover { backgr ...

Use setTimeout and setInterval with the initial input without parentheses or double quotation marks

<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> var count=0; function increaseCount(){ document.getElementById('txt').value=count; count++; setTimeout(increaseCount(),1000); } </script> </head&g ...

Displaying overlay when sidebar menu is expanded

I am working on creating a smooth overlay transition for when the sidebar menu opens and closes. When the overlay is clicked, I want the menu to close. This is what I have so far: $(document).ready(function() { $('#menu-toggle').click(fun ...

What is the reason behind Chrome's fullscreen mode turning the background black?

I created a webpage with full-screen functionality and made sure to use the correct CSS properties to ensure that my gradient background covers the entire screen perfectly. However, I encountered an issue when clicking the full-screen button in Chrome - th ...

Glowing CSS animation surrounding a PNG image

.zuphologo { padding-top: 33%; padding-bottom: 2%; } .fx { box-shadow: 0px 0px 100px 4px #fff; animation: glow 1.5s linear infinite alternate; } @keyframes glow{ to { box-shadow: 0px 0px 30px 20px #fff; } } <div class="container"> ...

How can I position an element at the bottom of a page using VueJS and Bootstrap CSS?

https://i.sstatic.net/ojanG.png I am trying to move my footer (Copyright statement) to the bottom of the page. However, it is creating some extra white space beneath the footer. How can I eliminate this additional white space? This issue is occurring in ...

Every key must be a string or number; received a function instead

I encountered a peculiar situation while working with Cucumber: Scenario Outline: Protractor and Cucumber Test InValid Given I have already...... When I fill the <number> .... Examples: | number|... | 3 |... |4 |... Moreover, I ...

A straightforward development and production build to incorporate HTTPS for a static website created with React and Express

Is there a straightforward method to create a static web page and Node backend where the Node server runs in HTTPS during development but not in production? How can the static web page point to https://localhost/foo in dev mode, and simply /foo in producti ...

hyperlinked text that automatically updates with the current date (using metarefresh)

I want to insert a date variable into a URL based on the current date. Specifically, I am looking to create a link from SharePoint that directs a user to the relevant files in a shared drive. My initial idea is to use an HTML page with a meta refresh that ...

The alignment of Flex Divs is off despite having identical heights

I'm facing an issue where divs are not staying at the top of their parent div if the image they contain does not have the same height as the others. Within my navbar, I have icons of varying sizes placed inside divs using display: flex to vertically ...