What is the best way to display text below a div element without disrupting the layout of other items in the

I am facing a minor issue with my design. My current skill set includes only CSS/HTML, and I want to incorporate some extra "wow factor" into one of my designs. To achieve this, I have been exploring jQuery snippets shared by others who have attempted similar enhancements. The problem arises when the text appears underneath when an item is hovered on - causing the other items in the list to move down, even though they all contain the same text. This peculiar behavior stems from the fact that the text is hidden until it's hovered upon, making it seem as if it doesn't exist.

These images should provide better clarity:

The two distinct states :

http://gyazo.com/6f736e7ef79409dbd3398facb03dcf5c.png

To clarify: it is the other boxes that shift downward, while the box with the acorn remains in its original position.

If you wish to view the code I used, you can do so here:

http://codepen.io/redhotfusion/pen/ipocE

Below is the relevant CSS:

.t_s_ul {

list-style-type:none;
width:90%;
padding-left:5px;
margin-left:-10px;
margin:0 auto;

}


.t_s_li {

  width:70px;
  height:70px;
  border:4px white solid;
  display:inline-block;
  border-radius:5px;
  margin:5px;
  position:relative;


}
.t_s_li:hover{

  transition:1s;
  background-color:white;

}

.type_icon {

  background:url("http://i.imgur.com/xix8EC9.png");
  width:100%;
  height:100%;
  background-size:100%;
  margin-left:-2px;

}

.type_icon:hover{

   transition:1s;
   cursor:pointer;
   background:url("http://i.imgur.com/e1IONg2.png");


}

.course_type_text {

  width:75px;
  color:white;
  font-size:0.85em;
  margin:0 auto;
  margin-top:0.5em;
  margin-left:-0.15em;
  font-family:"Open Sans" , arial;
  font-weight:400;

The HTML markup:

<ul class="t_s_ul">

    <li class="t_s_li">
      <div class="type_icon"></div>
      <DIV class="course_type_text">Course One</DIV>
    </li>
    <li class="t_s_li"></li>
    <li class="t_s_li"></li>
    <li class="t_s_li"></li>
</ul>

THE JS/JQUERY

$(function(){
$(".spire-menu").hover(function(){
  $(this).find(".menu-item").fadeIn();
}
                ,function(){
                    $(this).find(".menu-item").fadeOut();
                }
               );        
});

$(".spire-menu").on('mouseenter mouseleave', function () {
$(this).find('.box').fadeToggle(100);
});

Apologies if this seems like a beginner question, but we all have to start somewhere!

Any advice or assistance would be greatly appreciated!

Thank you,

-Valdis

Answer №1

To ensure your layout stays intact, include position: absolute; in the css for .course_type_text

By doing this, you eliminate any disruptions to the overall design.

You may even consider removing the fixed width from that class, as it will simply overlap other HTML elements.

Make sure to update your hover function with the following code:

$(".t_s_li").hover(function(){
  $(this).find(".course_type_text").stop(true, true);
  $(this).find(".course_type_text").fadeIn();
  }
  ,function(){
      $(this).find(".course_type_text").stop(true, true);
      $(this).find(".course_type_text").fadeOut();
  }
);    

This adjustment prevents animation queues when swiftly moving the mouse over the element multiple times.

Check out the demo here: http://codepen.io/anon/pen/fICiD

Answer №2

In order to align the li elements side by side using display:inline-block, you can add the following code to your class t_s_li:

.t_s_li {
  vertical-align:top;
}

You can see a demo of this in action here: http://codepen.io/anon/pen/jHbBq

By default, the vertical-align property for inline-block elements is set to baseline.

Answer №3

Consider including the following:

float: left;

within your .t_s_li class

http://codepen.io/anon/pen/oLIbz

Alternatively, you can also follow Dank and RononDex's suggestions... this is just one more approach to tackle it. :D

Answer №4

To achieve the desired result, add float:left to the CSS definition of .t_s_li

Your code should look like this:

.t_s_li {
  float:left;
}

Answer №5

Check out this CSS snippet:

.course_type_text {
  float: left; 
  width:75px;
  color:white;
  font-size:0.85em;
  margin:0 auto;
  margin-top:0.5em;
  margin-left:-0.15em;
  font-family:"Open Sans" , arial;
  font-weight:400;
  display:block;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

Feel free to view the demo 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 determine the total scrollable height of the browser's scroll bars?

I understand that $(window).scrollTop() provides the current position of the browser scroll bar, but how can I determine the total scrollable area? For example, if I scroll to the bottom and $(window).scrollTop() equals 300px, scrolling back to the top se ...

Limit the rotation of jQuery and CSS3 elements to always turn in a clockwise direction

Utilizing the jQuery transit plugin, I am rotating a block element with 4 navigation controls. Each time a nav item is clicked, the block rotates to the specified custom data attribute of that nav item - either 0, 90, 180, or 270 degrees. While I have suc ...

Clearing the input file: e.stopPropagation does not exist as a function

I found this awesome function on Stack Overflow to reset a file input element. <input type="file" id="image-file" /> Here is the JavaScript code: function clearFileInput(e) { e.wrap('<form>').closest('form').get(0).re ...

Discover the secret to opening two JPG files on YouTube using just one URL!

I was curious about the way YouTube thumbnails function. Here is an example thumbnail from a random YouTube video. There is an hqdefault.jpg in the URL, followed by some variables that indicate the size. If we remove or change these variables, a larger im ...

The issue of process.server being undefined in Nuxt.js modules is causing compatibility problems

I've been troubleshooting an issue with a Nuxt.js module that should add a plugin only if process.server is true, but for some reason it's not working as expected. I attempted to debug the problem by logging process.server using a typescript modu ...

ReactJS encountering an invalid dropzone element

Encountering the error "invalid dropzone element". I added var Dropzone = require('react-dropzone'); to my webpack.config.js file in hopes of activating the Dropzone element. This is what is included in my JavaScript file, copied from a Gith ...

Attempting to modify the background hue of a Bootstrap 5 Button using javascript

I've been experimenting with changing the background color of a bootstrap 5 button using JavaScript. While I've been able to successfully change the text color with JavaScript, altering the button's color has proven to be elusive. Below is ...

Set the div to have a position of absolute, disregarding any other parent divs that may also have position absolute set

Is there a way to bring an outsider class <div> to the front of all others, even when all <div> elements are set as position: absolute;? How can the .free-object, which is inside .left, overlap both .left and .right? I have tried using z-ind ...

When the mouse is clicked, display the date field; and when a date is chosen,

I have a date displayed as plain text. When I click the 'change' button, a datepicker should appear below it. After selecting a date, the datepicker should be hidden and the date in the plain text should be updated accordingly. <span id="disp ...

The top navbar does not stay fixed when the page is scrolled

Having some trouble with my navbar. Here is the code I'm using: <nav id="strumenti" class="navbar navbar-expand-sm navbar-light bg-light sticky"> <a class="navbar-brand" href="#"> <img src="C:\Users\Fabry\De ...

Issue with Event Listeners Not Reattaching Upon Clicking "Play Again" Button in Rock-Paper-Scissors Game

Description: I have created a Rock-Paper-Scissors game using HTML, CSS, and JavaScript. The game functions properly initially, allowing users to select their choice and play against the computer. However, after completing a game and clicking the "Play Agai ...

Ways to initiate a new animation once another one has concluded

I am looking to initiate a jQuery animation once another one has completed. Initially, there is a slide down effect towards the second navigation bar: $(".navigation-bar1").click(function() { $('html,body').animate({ scrollTop: $(". ...

Navigating with React Router using URL parameters

After implementing react router with a route path taskSupport/:advertiserId that includes parameters, I encountered an issue when trying to access the link http://localhost:8080/taskSupport/advertiserId. My browser kept returning 404 (Not found) errors for ...

The first generation iPad, CSS3 transformations, and the constraints on image processing due to limited RAM

During my exploration of the original iPad on iOS 5.0.1, I stumbled upon some peculiar quirks that appear to be linked to the number of images being loaded into the browser simultaneously. I noticed certain things rendering at half resolution or even lowe ...

"Implementing a Modular CSS Approach and Uniform Styling Across Your App

How can we handle the scenario of implementing specific styling for h1 tags within a modular CSS approach? In the past, this would have been achieved through inheritance in a single stylesheet. For example: .h1 { font-size: 3rem; /* more styles */ } .h2 { ...

A guide to aligning text on the right side of an image with HTML and CSS

Looking for assistance to align text on the right side of an image at the same level. Below is the code I have: <a class="following-row" href="index-2.html?pid=2306"> <img alt="Girls logo" src="photos/users/35257/resized/9fd79 ...

Explore our collection of videos featuring exclusive content on our video gallery. Please note

I am attempting to create a video gallery using YouTube videos. Here is the current code I have: //html... <div id="videogal" ></div> //javascript //initializing the gallery //mplv is an array, retrieving data after a database query //mplv[ ...

Strange glitch in the rendering of rectangles on HTML5 canvas?

While experimenting with pre-rendering sprites using HTML5 canvas, I encountered some strange behavior that appears to be a rendering bug. The issue can be seen in the following minimal example: var CT = document.getElementById("myCanvas").getContext("2 ...

Information is not stored within an array

After receiving data from an API, I attempted to store it in an array. However, when I tried to print the array, it was empty. The data retrieved is in JSON format. fetch("url") .then((response) => response.json()) .then((data) => ...

How can we implement the MUI snackbar to only show when a successful login occurs in ReactJS?

How can I display the material-ui snackbar in ReactJS only upon successful login? What approaches can be used to achieve this in ReactJS? ...