Troubleshooting problem with CSS borders in Microsoft Edge Browser

I am currently working on implementing the concept found at the following link: https://www.w3schools.com/howto/howto_js_tabs.asp, but with the additional feature of borders around the elements.

However, I have encountered an issue specifically with Microsoft Edge where the side borders disappear when selecting Tokyo or hovering over Paris. This behavior is not observed in Chrome and Firefox.

Below is the code snippet that I am using:

<!DOCTYPE html>
<html>
<!-- Tabs by Aubrey Bourke 2019 -->

<head>
...
    </style>
</head>
<body onload="openCity(event, 'London')">

...
   </script>
</body>
</html>

I am seeking assistance in understanding why this issue occurs with Microsoft Edge and if there are any potential solutions to address it. Any insights or suggestions would be greatly appreciated.

Answer №1

While I may not have a direct answer to your question, I want to offer an alternative approach that is compatible with classic Edge and other modern browsers.

Although there might be better methods for marking up and styling these tabs, I decided to stick with the markup you provided as a starting point. This approach may not align exactly with what you were hoping for, but it could still be beneficial in exploring relevant issues (such as separating styling from JavaScript).

In my solution, I relied heavily on CSS for styling and aimed to streamline the JavaScript functionality. Typically, I try to avoid applying styles directly to elements using JS unless there is a specific requirement that mandates such an approach. While this is generally considered a best practice, there may be reasons unknown to me for why you implemented it that way.

Wishing you the best of luck with your project.

    function openCity(evt, cityName) {
      var i, tabcontent;
      tabcontent = document.getElementsByClassName("tabcontent");
      for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
      }
      document.getElementById(cityName).style.display = "block";
      var toggleTabs = function (e) {
        var active = document.querySelector('.active');
        if (active) {
          active.classList.remove('active');
        }
        e.currentTarget.classList.add('active');
      }
      var tablinks = document.querySelectorAll(".tablinks");
      var tablinksSet = Array.from(tablinks);
      tablinksSet.forEach(function (item) {
        item.addEventListener('click', function (e) {
          toggleTabs(e);
        })
      })
    }
 body {
      font-family: Sans-serif;
      background-color: white;
    }

    /* Style the tab */
    .tab {
      position: relative;
      border-style: solid;
      border-width: 1px;
      border-color: #ccc #ccc transparent #ccc;
      background-color: #f1f1f1;
    }

    /* Style the buttons inside the tab */
    .tab button {
      background-color: inherit;
      float: left;
      margin-top: -1px;
      border: 1px solid transparent;
      outline: none;
      cursor: pointer;
      padding: 16px 16px;
      transition: 0.3s;
      font-size: 17px;
      border-bottom: 1px solid #f1f1f1;
      border-top: 1px solid #ccc;

    }

    /* Change background color of buttons on hover */
    .tab button:hover {
      /*background-color: #ddd;*/

    }

    /* Create an active/current tablink class */
    .tab button.active {
      position: relative;
      background-color: white;
      border: 1px solid #ccc;
      border-bottom-color: white;
    }

    .tab button.active::after {
      content: "";
      position: absolute;
      display: block;
      width: 100%;
      height: 2px;
      bottom: -2px;
      left: 0;
      background-color: white;
      z-index: 50;
    }

    .tab button:first-child {
      margin-left: -1px;
    }

    .tab button:not(.active):first-child {
      border-left-color: #ccc;
    }

    .tabcontents {
      width: 500px;
      float: left;
    }

    /* Style the tab content */
    .tabcontent {
      position: relative;
      z-index: 1;
      display: none;
      padding: 6px 12px;
      margin-top: -1px;
      background-color: white;
      border-style: solid;
      border-width: 1px;
      border-color: #ccc #ccc #ccc #ccc;
    }

    .cf:before,
    .cf:after {
      content: " ";
      display: table;
    }

    .cf:after {
      clear: both;
    }

    .container {
      width: 500px;
    }
<!DOCTYPE html>
<html>

<head></head>

<body onload="openCity(event, 'London')">
  <div class="container">
    <div class="tab cf">
      <button id="one" class="tablinks active" onclick="openCity(event, 'London')">London</button>
      <button id="two" class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
      <button id="three" class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
    </div>
    <div class="tabcontents">
      <div id="London" class="tabcontent">
        <h3>London</h3>
        <p>London is the capital city of England.</p>
      </div>
      <div id="Paris" class="tabcontent">
        <h3>Paris</h3>
        <p>Paris is the capital of France.</p>
      </div>
      <div id="Tokyo" class="tabcontent">
        <h3>Tokyo</h3>
        <p>Tokyo is the capital of Japan.</p>
      </div>
    </div>
  </div>
</body>
</html>

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

Achieve a responsive layout by dynamically sizing child div elements to fill their parent container using percentage-based margins and

I'm having trouble getting the child divs to stretch to the parent, and I'm not sure if I need to specify a % width on #fullpage-content even though #middle is set to 76%. I seem to have forgotten... Would you like to check out this link where c ...

Styling the footer to sit at the bottom of the page with a wider width, overlapping the content

I've encountered an issue where the footer of my webpage overlaps the content when the main content is long and users cannot scroll properly. Additionally, I've noticed that the width of the footer is larger than the header of the website. Below ...

CSS for a navigation menu with underlined links

I am attempting to create an underline effect when hovering over a link. However, I am facing an issue where the underline does not align perfectly with the line below it. Can someone please guide me on how to modify this CSS so that when the link is hov ...

Design a circular progress bar with a cut-off at the bottom

Does anyone have suggestions on how to create a circular progress bar with cropping at the bottom, similar to this example: PROGRESS BAR? I've been searching for a component like this but haven't had any luck. Any ideas, especially utilizing Mate ...

Surprising CSS overflow error

Recently, I've encountered a CSS overflow issue while working on a responsive webpage. The problem seems to be stemming from the navigation menu. The declaration of "overflow-x: hidden" is specifically causing the trouble... Initially, I suspected i ...

How can I create a dynamic height for a scrollable div?

How can I build a section with a defined height that contains a sticky header (with a dynamic height) and a scrollable body? I want the body to be scrollable, but due to the header's changing height, I'm unable to set an exact height. What should ...

The minimum height of the IE element could not fully expand within its flex container that was set to absolute positioning

Creating a webpage with a full-page layout using a content session that spans the entire height of its container is my current project. To achieve this, I have implemented the following: The content's container (div.inner) is set to be absolute-posi ...

What is the best way to align a <div> element below another without being on the same line?

I'm currently working on developing a snake game. My focus right now is figuring out how to make the body parts of the snake follow the head and be positioned after it. <!--Player--> <div class="snake"></div> So here we have the sn ...

"Facing a dilemma with Javascript's Facebox getElementById function - not fetching any

Utilizing facebox, I am initiating a small modal dialog with a form and attempting to retrieve the value from a text field on that form using javascript. Below is the HTML code: <div id="dialog-form95" style="display:none"> <div class="block"> ...

Dynamic row height in MUI DataGrid

I'm currently utilizing the MUI DataGrid component, and I have a specific behavior in mind that I'd like to achieve: When there is a small number of rows present, I want the table to only occupy the necessary space for those rows. On the other h ...

How does Angular5 perform with Bootstrap4?

Currently working on an Angular5 application and considering integrating bootstrap into it. I imported Bootstrap4, which includes dependencies on JQuery and Popper.js. Another option I came across is utilizing CSS grid for more versatility compared to boo ...

Place the first paragraph within a div above another paragraph in the same div

Presently, I have this item: https://i.stack.imgur.com/0dBd9.png however, my objective is to achieve this look: https://i.stack.imgur.com/NEBZf.png The code snippet in question is as follows: .bonus-div { width: 290px; height: 29px; ma ...

Using HTML or JavaScript to generate a multitude of identical HTML elements on a webpage

I am currently designing a page that requires the presence of numerous tree illustrations with leaves, spanning across the width at the bottom of the page. I have considered two methods to achieve this. One option is to create a single set of trees and lea ...

Issue with the Ajax auto-complete feature in Internet Explorer

I am facing an issue with my "ajax suggestion list" getting hidden behind the "select menu" located right below the text box that triggers the ajax function. This problem only occurs in IE 6.0, while it works fine in other browsers. I have already disabled ...

Using the Position Sticky feature in Next.js

As a newcomer to sticky elements, I decided to implement a sticky sidebar in my project. Unfortunately, after copying and pasting some code snippets related to sticky sidebars, it seems that the functionality is not working as expected. <Layout title= ...

Aligning HTML headers in a horizontal manner

Can anyone help me out here? I have a div containing 4 elements that are currently stacked on top of each other. I want them to be aligned horizontally instead. The div's ID is #ninesixty. Thank you in advance! HTML <header> <div id="ni ...

Adjust the font size based on the dimensions of the container

I'm currently working on a script that dynamically sets the font-size based on the container's dimensions and the length of the text. This is what I have implemented so far. window.onload = function () { var defaultDimensions = 300; ...

Positioning a sticky footer in a dual-column design

This updated post is a revised version of the one found at this link. I aim to provide a clearer explanation of my issue compared to the previous post. The problem revolves around the placement of the footer in two different scenarios. Scenario 1: The fi ...

Display PHP output within a styled CSS box

<html> <head> </head> <style type="text/css"> .yellow-box { position:absolute; top:100px; left:500px; width:300px; height:300px; background:yellow } </style> <div class = "yellow-box" > </div ...

Emphasize the content within the table cell

Currently, I am working with an HTML table that is being generated by Java. My goal is to highlight the text within a table cell without changing the background color of the entire cell. I should mention that I am aware of the option to achieve this by ma ...