What measures can be taken to keep the rightmost element from moving when hovered over?

While I am generally happy with the layout, there seems to be a slight jump to the left when hovering over the right-most image (you need to click "show images" to view them). Strangely, this issue does not occur with the last row of images. Any suggestions or guidance would be greatly appreciated.

To better illustrate the problem, here is a Codepen link: https://codepen.io/anon/pen/OmeNRa?editors=0110

var showImages = $("#showImages");
var hideImages = $("#hideImages");
var images = $("#images");
var overlay = $("#overlay");
var docHeight = $(document).height();
var writtenContent = $("#writtenContent");
var counter = 0;
var messageBox = $("#messageBox");
var sendMessage = $("#sendMessage");

showImages.click(function() {
  counter++;
  $(this).html("Show Images");
  if (counter % 2 > 0) $(this).html("Hide Images");
  $("body").toggleClass("blackout", 300);
  images.slideToggle({
    direction: "up"
  }, 600);
  writtenContent.slideToggle({
    direction: "up"
  }, 600);
});

sendMessage.click(function() {
  messageBox.slideToggle({
    direction: "up"
  }, 500);
});

$(document).on("mouseenter", "span img", function() {
  $(this).addClass("fade").siblings().show();
});
$(document).on("mouseleave", "span img", function() {
  $(this).removeClass("fade").siblings().hide();
});
.nav {
  height: 8vh;
  background: linear-gradient(-45deg, purple, purple, indigo);
  color: white;
  font-family: helvetica;
  font-size: 20px;
  position: fixed;
  left: 0;
  width: 100%;
  z-index: 999;
}

#topNav {
  top: 0vh;
}

#bottomNav {
  bottom: -8.1vh;
  transform: translateY(-100%);
}

#content {
  padding-top: 8vh;
  padding-bottom: 8vh;
  margin: 0 auto;
}

#images {
  display: none;
  z-index: 100;
  bottom: 0;
  text-align: center;
}

#images span {
  position: relative;
  text-align: center;
}

#images span img {
  height: 100px;
  width: 100px;
}

.blackout {
  background-color: black;
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  -o-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}

.name {
  display: none;
  color: white;
  left: 0;
  position: absolute;
  bottom: 200%;
  width: 100%;
  font-weight: bold;
  pointer-events: none;
}

.fade {
  opacity: .2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="nav" id="topNav">
</div>
<div id="content">
  <div id="writtenContent">
    <p>This page's written content starts here..</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
                ...
    <p>END of page's written content.</p>
  </div>;

  <div id="images">
              ...
            images and titles are listed here
              ...
      </div>

</div>

<div class="nav" id="bottomNav">
  <button id="showImages">Show Images</button>
</div>

Answer №1

The issue lies in your .images>span having a default display:inline. Additionally, your centering method is reliant on the height of the inline span, which can easily break if the line-height changes, impacting proper centering (especially when the image height is adjusted).

To resolve this problem, I suggest the following:

#images span {
  display: inline-block;
}
.name {
  bottom: 50%;
  text-align: center;
  transform: translateY(50%);
}

Your updated code snippet:

var showImages = $("#showImages");
var hideImages = $("#hideImages");
var images = $("#images");
var overlay = $("#overlay");
var docHeight = $(document).height();
var writtenContent = $("#writtenContent");
var counter = 0;
var messageBox = $("#messageBox");
var sendMessage = $("#sendMessage");

showImages.click(function() {
  counter++;
  $(this).html("Show Images");
  if (counter % 2 > 0) $(this).html("Hide Images");
  $("body").toggleClass("blackout", 300);
  images.slideToggle({
    direction: "up"
  }, 600);
  writtenContent.slideToggle({
    direction: "up"
  }, 600);
});

sendMessage.click(function() {
  messageBox.slideToggle({
    direction: "up"
  }, 500);
});

$(document).on("mouseenter", "span img", function() {
  $(this).addClass("fade").siblings().show();
});
$(document).on("mouseleave", "span img", function() {
  $(this).removeClass("fade").siblings().hide();
});
.nav {
  height: 8vh;
  background: linear-gradient(-45deg, purple, purple, indigo);
  color: white;
  font-family: helvetica;
  font-size: 20px;
  position: fixed;
  left: 0;
  width: 100%;
  z-index: 999;
}

#topNav {
  top: 0vh;
}

#bottomNav {
  bottom: -8.1vh;
  transform: translateY(-100%);
}

#content {
  padding-top: 8vh;
  padding-bottom: 8vh;
  margin: 0 auto;
}

#images {
  display: none;
  z-index: 100;
  bottom: 0;
  text-align: center;
}

#images span {
  position: relative;
  text-align: center;
   display: inline-block;
}

#images span img {
  height: 100px;
  width: 100px;
}

.blackout {
  background-color: black;
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  -o-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}

.name {
  display: none;
  color: white;
  left: 0;
  position: absolute;
  bottom: 50%;
  width: 100%;
  font-weight: bold;
  pointer-events: none;
  text-align: center;
  transform: translateY(50%);
}

.fade {
  opacity: .2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="nav" id="topNav">
</div>
<div id="content">
  <div id="writtenContent">
    <p>This page's written content starts here..</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>Page written content goes here.</p>
    <p>END of page's written content.</p>
  </div>

  <div id="images">
    <span>
          <img src="https://pp.walk.sc/map_tiles/walkscore/v3/17/4512/6478/14.png">
          <div class='name'>Image Title</div>
        </span> 

    // more image spans to follow...

  </div>

</div>

<div class="nav" id="bottomNav">
  <button id="showImages">Show Images</button>
</div>

It's important to note that <div>s within <span> elements are technically not allowed. While this rule may be relaxed in the future due to its widespread use, for now, it's best to adjust your markup for validation purposes.

Answer №2

The alignment of the text is being adjusted to the left. Modifying the CSS code mentioned below resolves the problem.

#images{
 display:none;
 z-index:100;
 bottom:0;
 text-align:left; /* Updated from center to left */
}

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 a JavaScript Library in your Scala.js Project: A Step-by-Step Guide

I am currently following a tutorial on setting up dependencies in my Scala.js project. Here is the link to the tutorial: First and foremost, I have organized my project setup as shown below: https://github.com/scala-js/scalajs-cross-compile-example Wi ...

Customizing the Background of an Input Box

How can I create an input box with a specific background? I have tried the following code but it's not displaying properly. What is the correct way to achieve this? In addition, I need to create variations of this button as described below: I wa ...

Utilize jQuery to load a separate external sites div into an iframe

I have a department website that caters to a specific audience. I am interested in including a set of related links from an external site at the conclusion of each article. The links will be organized within a div, like so: <div id="linktoc"><a h ...

Displaying Values/Marks in a Unique Order with Material-UI Slider Component

The default behavior of the Material-UI slider is to display marks/values in ascending order from min to max For instance, if you have a slider configured like this: const marks = [ { value: 1, label: '1' }, { value: 2, lab ...

Tips for aligning text to the right and keeping it in line with another section

I have a code snippet and I'm aiming to align the caption for my "DigDug" game directly below the game itself, perfectly lined up horizontally. The id for the caption is "#DigCaption" and the id for the game is "#DigDug". Could anyone provide guidance ...

Using mui-datatables to display an array of objects

Seeking help from users of mui-datatables. While it successfully handles data in the form of an array of strings, there is an issue when trying to load an array of objects resulting in the following error: bundle.js:126379 Uncaught (in promise) TypeEr ...

Develop a JavaScript application that contains a collection of strings, and efficiently sorts them with a time complexity of O(nlog n)

Seeking assistance in developing a JavaScript program that contains an array of strings and must sort them efficiently in O(nlog n) time. Grateful for any guidance... ...

What strategies does NPM/WebPack employ to handle duplicate dependencies across different version ranges?

I am working on an application that relies on various packages, each with its own set of dependencies. For instance, my app may require package@^1.0.0, while another package it uses may demand package@^1.5.1. When I build the app for production, will both ...

Learn how to hide elements on print pages conditionally in Vue.js using CSS or JavaScript

I am currently using the Vue framework to work on printing webpages for my application. I have an issue that needs a solution, which I will explain below. <template> <div id = "intro" style = "text-align:center;"> <div ...

Update a roster with AJAX following the addition or removal of a user

My goal is to implement two functions: Adding and Deleting a User from the database using Mongoose. However, when I run the code, I receive a 200 OK response but with an empty username. I suspect there might be an issue with the ajax calls. Can anyone hel ...

Differences between .php and .html: What causes variations in IE rendering?

After duplicating one of the HTML pages in my project, I simply changed the file extension from .html to .php. Surprisingly, all browsers display the page identically except for Internet Explorer (IE), which seems to handle the pages differently based on t ...

Modify the div's background color specifically with AngularJS

After creating a list using divs, my goal is to modify only the background color of the selected div when a user makes a choice from the list. I have accomplished this by defining two distinct CSS classes with the main difference being the background colo ...

Blending Angular5 and AngularJS in Polymer

We are considering launching two new projects - one using Angular 5 and the other utilizing Polymer. The second project is intended to serve as a component library for reuse in not only the Angular 5 project but also in other AngularJS projects. After res ...

What is the process for transforming conditional classes from clxs to cva format?

Looking for a way to convert the code snippet below into cva format... {items.map((item, index) => { const isActive = item.key === SOMETHING; return ( <div key={index} className={clsx( ...

Is there a way to automatically populate my second dynamic dropdown list on page load?

I am currently working on a dynamic drop down menu that consists of two lists. When the page initially loads, the second drop down list is empty. However, I would like both lists to be displayed by default. You can see an example of the issue I'm faci ...

Arranging hierarchical data in JavaScript

After populating the hierarchy data, it is structured as follows: Here is a screenshot: I am looking to sort this data. Currently, I have a flat data object for rendering purposes. For example, my rendering object looks like this: renderedobjects=[ {1,. ...

Jesting around with mocking console.error leads to test failures

The Issue: Currently, I am working on testing React components using Jest and Enzyme. In order to check for properties in development, I have incorporated the prop-types module. The prop-types module relies on console.error to alert when mandatory props a ...

Utilize Vue.js to selectively display or manipulate objects with a

I am currently working on a Vue.js component page that receives data from my backend. The page consists of three different filters/states that users can choose from: Unlabeled, Completed, and Skipped. Unlablled Completed Skipped My approach involves usin ...

The daterangepicker reigns supreme above all other elements

Just a heads up, I am utilizing daterangepicker from this link: . Recently, I encountered an issue where the input field was overlapping with other elements like bootstrap Modals or menus. <div class="col-md-3 form-group"> <div class=&qu ...

Tips for animating a nested array using jQuery

I have a border that is 9x9 with lines, columns, and squares, similar to a Sudoku border. I want to animate it, but I encountered some issues when trying to run multiple animations simultaneously. To solve this problem, I decided to animate one array of el ...