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

Enhance Your Highcharts Funnel Presentation with Customized Labels

I am working on creating a guest return funnel that will display the number of guests and the percentage of prior visits for three categories of consumers: 1 Visit, 2 Visits, and 3+ Visits. $(function () { var dataEx = [ ['1 Vis ...

Creating a dual-column checkbox design with CSS only

I'm working with a dynamically generated form element that can only be styled using CSS. I need help achieving a specific layout without making any HTML changes, except for the classes. The "element" and "formField" classes are common and cannot be mo ...

Applying a specified style to a pseudo element using the ::after selector to display an

Can anyone help me with adding a pseudo element ::after containing an icon (from FontAwesome) to my Bootstrap Vue ProgressBar? I want this icon to be dynamic and move along the progress bar line when I click. Here is my current implementation, where the Pr ...

Center Items in Flexbox, Implementing React Material with React

In my React App, I am utilizing flexbox and React Material to align the searchbar and clear button on the same line with space between them. Here is the link for reference: CLICK HERE <div className={classes.searchBarSection}> <Paper com ...

Utilizing jQuery and CSS to make an entire div clickable, and activate an 'a' tag hover state upon hovering

Looking to create a clickable link for the .wrapper div that directs users to the location of a.icon. Want the .wrapper div to activate the a.icon:hover state when hovered over, not just when hovering over the icon itself. Any assistance would be highly a ...

Center a grid of cards on the page while keeping them aligned to the left

I have a grid of cards that I need to align in the center of the page and left within the grid, adjusting responsively to different screen sizes. For example, if there are 10 cards and only 4 can fit on a row due to screen size constraints, the first two ...

The collapsible hamburger navbar is unresponsive and fails to collapse

Currently, I am working on a project that requires my navigation bar to be scaled down to a hamburger menu for mobile view. I have managed to do most of it, but for some reason, the navigation is not collapsing within the hamburger bar. I have been tweakin ...

Incorporating HTML5 audio elements in JavaScript

I am working on a project where I need to create a grid of 16 audio files with separate links for each in HTML, CSS and JavaScript. Each box in the grid should link to a different audio file. My initial thought was to use a table to achieve this, so I cre ...

Leverage jquery to adjust the height or width of an element depending on which dimension is larger

I'm a beginner in jquery and html and am currently developing a gallery webpage. The functionality involves setting the selected image as the page background and then scrolling vertically based on the mouse pointer's position. This works well for ...

Clickable regions in Internet Explorer 7 that lack a specific width

Is there a way to make the clickable area of links always stretch to the parents container when the parent container does not have a fixed width? For example, check out this JSFiddle. In Firefox, the link stretches with the text and the li tag, but in IE ...

Is there a way to create a transparent background for my website without affecting the visibility of the content such as images and text?

I'm currently working on a website for a school project, and I've run into a minor issue. I can't seem to make the background of the body transparent without affecting the content within it. Below is my HTML code: <html> <head> ...

Excessive Font Awesome Icons causing navigation bar to appear oversized

My Font Awesome icons are causing my navbar to expand in height. Despite resetting all margin and padding to 0, adjusting the margins and paddings of the icons has not helped. I even tried setting negative top and bottom margins/paddings. I want the icons ...

Issues with table nesting functionality

I'm attempting to organize tables in a nested manner, instead of placing a table within each cell. My engineers have advised against simply styling the table to appear nested, and suggested that it would be more effective to wrap each header around th ...

unable to modify the content within a div by clicking on a link

Lately, I've been experimenting with a code snippet I found on this fiddle: http://jsfiddle.net/unbornink/LUKGt/. The goal is to change the content of a div when clicking on links to see if it will work on my website. However, no matter which link I c ...

Having issues with object-fit: cover not functioning properly in Safari browser

Encountering a browser support issue at the moment. Everything is functioning as expected on Firefox and Chrome, but Safari is causing problems with images. Currently, the image size is set using "object-fit: cover" and working properly on Chrome/Firefox. ...

Steer clear of altering line spacing in CSS

Here is the HTML structure that I am working with: <div id="id1"> <h1>my name </h1><h3><a href="mailto:myemail_id"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff92869a929e9693969bbf878685d19 ...

Styling CSS: Adjusting font sizes for placeholders and text boxes

I am struggling with styling an input field to have a font size of 45px while the placeholder text inside it should be 18px and vertically aligned in the middle. Unfortunately, my current code is not working in Chrome and Opera. Can anyone offer a solutio ...

The CSS effect fails to take effect following an AJAX response

After a successful ajax response, I am attempting to apply a jQuery .css effect. However, it seems that this process is not working as expected because I am trying to retrieve the height of a newly created element and then applying it to another newly crea ...

Set a unique class for several elements depending on a given condition

Is there a way to assign a color class based on the element's value without looping through all elements? Check out my jsfiddle HTML <div> <ul> <li class="MyScore">90</li> <li class="MyScore"> ...

Is it possible to utilize a .css file as the origin with @font-face?

Received a shortened path to a Gotham font... https://cloud.typography.com/[path shortened]/css/fonts.css Attempting to use it in a @font-face definition but facing issues with the src format: @font-face { font-family: 'Gotham'; src: url(" ...