When hovering over a select element within a grid-area that has overflow set to scroll, Safari unexpectedly jumps to the

Encountering a strange issue that I can't seem to figure out. When testing the code in Safari, hovering over the select field causes the .page div to scroll to the top.

This behavior only occurs when .page is within a grid layout and there's a select:hover rule in place. Height constraints without the grid structure work fine without this scrolling problem.

If anyone has any insights into why this might be happening, I'd appreciate some guidance.

Just to note, this works as expected in Chrome and Firefox.

.site {
  display: grid;
  grid-template-areas: "sidebar header""sidebar page";
  grid-template-columns: auto 1fr;
  grid-template-rows: 60px 1fr;
  height: 200px;
}

aside {
  grid-area: sidebar;
  background-color: #e3e3e3;
  color: transparent;
}

header {
  grid-area: header;
  background-color: #cccccc;
  color: transparent;
}

.page {
  grid-area: page;
  overflow: scroll;
  background-color: #fff;
}

.spacer {
  padding: 100px 0;
}

select:hover {
  color: red;
}
<div class="site">

  <aside>
    Sidebar
  </aside>
  
  <header>
    Header
  </header>
  
  <main class="page">
    <div class="spacer">Scroll down...</div>
    <label for="test">Hover the select</label>
    <select name="test" id="test">
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
      <option value="2">Value 3</option>
    </select>
    <div class="spacer">More content...</div>
  </main>
  
</div>

Answer №1

Great news, I've managed to solve the issue and wanted to share my solution in case it helps someone else.

Solution

By setting max-height: 100% on the .page div, everything should function as intended. You can test this in Safari to confirm.

.site {
  display: grid;
  grid-template-areas: "sidebar header""sidebar page";
  grid-template-columns: auto 1fr;
  grid-template-rows: 60px 1fr;
  height: 200px;
}

aside {
  grid-area: sidebar;
  background-color: #e3e3e3;
  color: transparent;
}

header {
  grid-area: header;
  background-color: #cccccc;
  color: transparent;
}

.page {
  grid-area: page;
  overflow: scroll;
  max-height: 100%;
  background-color: #fff;
}

.spacer {
  padding: 100px 0;
}

select:hover {
  color: red;
}
<div class="site">

  <aside>
    Sidebar
  </aside>
  
  <header>
    Header
  </header>
  
  <main class="page">
    <div class="spacer">Scroll down...</div>
    <label for="test">Hover the select</label>
    <select name="test" id="test">
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
      <option value="2">Value 3</option>
    </select>
    <div class="spacer">More content...</div>
  </main>
  
</div>

.site {
  display: grid;
  grid-template-areas: "sidebar header""sidebar page";
  grid-template-columns: auto 1fr;
  grid-template-rows: 60px 1fr;
  height: 200px;
}

aside {
  grid-area: sidebar;
  background-color: #e3e3e3;
  color: transparent;
}

header {
  grid-area: header;
  background-color: #cccccc;
  color: transparent;
}

.page {
  grid-area: page;
  overflow: scroll;
  background-color: #fff;
}

.spacer {
  padding: 100px 0;
}

select:hover {
  color: red;
}
<div class="site">

  <aside>
    Sidebar
  </aside>
  
  <header>
    Header
  </header>
  
  <main class="page">
    <div class="spacer">Scroll down...</div>
    <label for="test">Hover the select</label>
    <select name="test" id="test">
      <option value="1">Value 1</option>
      <option value="2">Value 2</option>
      <option value="2">Value 3</option>
    </select>
    <div class="spacer">More content...</div>
  </main>
  
</div>

Answer №2

If you happen to come across this issue in the future and find that the suggested solution isn't resolving it, I suggest taking a look at this helpful answer that worked like a charm for me:

For my situation, the scroll to top was triggered by any focus event - buttons, text inputs, and more...

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

Utilizing jQuery to convert letter input values into English: a step-by-step guide

I am developing a basic web application using Jquery. In this application, I aim to restrict user input language. For instance, if a user enters the Russian letter б in the input field, I want to automatically convert it to an English character. Below is ...

Guide to updating code within <head> sections for all HTML documents within a folder utilizing R

I need a streamlined method to edit the code within the <head> and </head> tags for numerous .html files located in the same directory. It is essential that I use R for this task, as it is part of an rmarkdown project for my classroom, and I w ...

React Nested Grid with Material-UI

https://i.stack.imgur.com/toxDA.jpg I am striving to replicate the layout demonstrated in the image below So far, I have the following code snippet: <Grid container justify=“space-between”> <Grid container item> <Grid ite ...

What is the best way to implement nested iterations in Jade?

ul li a(href='') menu1 li a(href='') menu2 ul li a(href='') sub-menu2 li a(href='') menu3 ul li a(href=&apos ...

When editing html files in Vim, the javascript indent filetype plugin is sourced unexpectedly

After experimenting with my vim settings, I noticed an unexpected behavior. When editing html files in vim, both the indent/javascript.vim and indent/html.vim filetype plugins seem to be sourced simultaneously. Is this intentional or a bug? How can I ensur ...

I'm looking for the location of Angular Materials' CSS directives. Where can I find them?

Currently, I am using components from https://material.angularjs.org/latest/ for a searcher project. One specific component I am working with is the md-datepicker, and I would like to implement some custom styles on it such as changing the background colo ...

Fade in images smoothly

Currently, I am in the process of creating a visually appealing image "slider" for a landing page on one of my websites. The slider that I have already created is fully functional and successful, but I am looking to take it up a notch... My goal is to inc ...

Unable to view new content as window does not scroll when content fills it up

As I work on developing a roulette system program (more to deter me from betting than to actually bet!), I've encountered an issue with the main window '#results' not scrolling when filled with results. The scroll should always follow the la ...

What is the best way to ensure that an input field and a button stretch across the entire row in a Bootstrap form?

I need assistance with aligning the Post button to the right and having the text field for tags occupy the entire left section of the row within a Bootstrap 3 form. The form markup is shown below: https://i.sstatic.net/401RU.png Below is the complete cod ...

Having trouble getting CSS animation to work on Mozilla using mozAnimationName?

<style> @keyframes shake { 0% { -moz-transform:scale(0);opacity:0; } 25% { -moz-transform:scale(1.3);opacity:1; } 50% { -moz-transform:scale(0.7);opacity:1; } 75% { -moz-transform:scale(2); ...

Utilizing AngularJS to display numerous charts on a single webpage

Currently, I am looking for a solution to display multiple charts on the same page. My goal is to showcase individual performance through each chart for different persons. After exploring Google Charts, I noticed that it requires unique "id" attributes w ...

Ajax, silently transmitting data without refreshing the page

In one of my files, A.php, there is basic information that includes a form with an input field for email and a button. When the user clicks on the button, it triggers a function in JavaScript. <div class="col-md-8"> <input type="email" class="f ...

Adaptive Website displayed within an iframe

Currently, I have a responsive website that can be viewed here. The main objective is to embed this site into an iframe while maintaining its responsiveness. I attempted embedding my site in JSFiddle for testing purposes, which you can see here. However ...

What is the best way to make the first <p> tags bold within an array?

I tried using ::first-line, but it bolds all the p tags in the array. What I want is to only bold the first p tag which contains "Hello". https://i.sstatic.net/l0Ss6.png <div v-for="item in first" :key="item.id"> <p cl ...

Fine-tuning the page design

I'm working on a registration page using Bootstrap-5 for the layout. Is there a way to place all elements of the second row (starting with %MP1) on the same row, including the last field that is currently on the third row? See image below: https://i. ...

Designing a dynamic class object for a material table

I am in need of assistance with creating an HTML table using data retrieved from an API. The structure of the data is as follows: { strTableName: "TestTable", strComment:"Approved", lstTableHeaders:[ {strFieldName : "Sl No.", strType:" ...

Ways to detect the use of vue.js on a webpage without relying on vue-devtools

One way to determine if the page is utilizing Angular or AngularJS is by inspecting window.ng and window.angular. Is there a similar method to identify whether Vue is being used on the page directly from the console, without relying on vue-devtools? ...

Footer gets in the way of gallery div

As a coding novice, I recently downloaded the Galereya JQuery script to use on my website. While it works well, I encountered an issue where it overlaps with other content on the page. Despite trying to adjust the overflow and position properties, I have b ...

How to place text on top of a thumbnail in Bootstrap using HTML

I've come across similar questions here, but none of the suggested solutions have worked for me. (I attempted making the image a background as recommended on how to display text over an image in Bootstrap 3.1, but it didn't seem to be effective) ...

A guide on extracting text enclosed by <a> and </a> tags using regular expressions

I have come across the following code: <a align="center" href="http://google.com"><b>Google Link<b></b></a> <a align="center" href="http://yahoo.com"><strong>Yahoo Link</strong></a> Now, I am looking ...