The adjustment in margin triggers a ripple effect on several div elements

My goal is to make my logo image move up on hover without affecting the text below it. However, I'm facing an issue where both elements are triggered simultaneously even though they are in different divs wrapped in a parent div. It seems like there might be a problem with the margins, as when I tried adjusting them, the behavior of the text elements became erratic.

Here's a Fiddle link

CSS:

.full-circle {
display:block;
margin:auto;
margin-top: 15px;
overflow: hidden;
height: 180px;
width: 180px;
border: 2px solid #FFF;
-moz-border-radius: 90px;
-webkit-border-radius: 90px;
background:#FDF5E6;
-webkit-transition: margin 0.2s ease-out; 
-moz-transition: margin 0.2s ease-out; 
-o-transition: margin 0.2s ease-out;
}

.full-circle:hover{margin-top: 2px;}

jQuery:

$('.full-circle').hover(
            function(){
                $(this).stop().animate(
                    {marginTop: '2'}, 20, 'linear'   
                );//end animate
            },//end function
            function(){
                $(this).stop().animate(
                {marginTop: '15'}, 20, 'linear'
                );//end animate
            }//end function
        );//end hover

Answer №1

To make the animation smoother for .full-circle, you can simply include the CSS property position: relative and then animate the top property instead of using margin-top.

$('.full-circle').hover(
    function(){
        $(this).stop().animate(
            {top: '-10'}, 20, 'linear'   
        );//end animate
    },//end function
function(){
    $(this).stop().animate(
        {top: '15'}, 20, 'linear'
        );//end animate
    }//end function
);//end hover

Check out the working demo here!

Answer №2

The reason for the text shifting upwards is due to both elements being part of the document flow, causing movement in one element to impact the position of the other.

Instead of modifying the margin of the circle, you can utilize position:relative; and adjust the top property with a negative value such as top:-20px; (or any desired amount) to move it upwards.

By adjusting the top, bottom, left, or right properties on a relatively positioned element, you can change where the element appears on the screen without disrupting its relationship with neighboring elements in the flow.

Answer №3

Creating a full circle with CSS is quite simple.

.full-circle{margin-top:15px; margin-bottom:15px}

.full-circle:hover{margin-top:2px; margin-bottom:28px}

.logo{overflow:hidden;}

You can achieve this without using JQuery, but if you prefer to use it, simply adjust the margin-top and margin-bottom properties accordingly.

If your element with the class .grey is being affected by filters creating extra padding, you can prevent this by adding .logo { overflow:hidden}

Test it out on this JSFiddle link.

Follow these instructions and everything should work smoothly.

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

When using jQuery to add an item to a List, it disappears immediately after

I am facing an issue with the code I have. Whenever I click on the "Add" button to add an item, it briefly appears in the list but then disappears. I'm having trouble figuring out why this is happening. $(document).ready(function() { $("#submitB ...

Retrieve and showcase Resident information upon clicking the view button through ASP.NET Core

UserDashboard.cshtml <table class="display table" id="ManageUser" style="width:100%"> <thead> <tr> <th>User ID</th> <th>Username</th> &l ...

Tips for positioning social media icons on the right side of the navigation bar

I need assistance aligning my social media icons with the navbar on the right side of the display. Can someone provide guidance? The first image shows the current layout, while the second image illustrates how I would like it to appear: http://imgur.com/a ...

Is there a way to automatically scroll to the top on refresh or load without using Jquery in AngularJs or Js?

One issue I'm facing is trying to set the page to scroll to the top when it loads. However, Chrome, IE, and Firefox are currently resetting the scroll position to where it was on the previous page. How can I achieve this? It appears that scrollTo doe ...

Methods for adjusting columns and rows in HTML5 tables

As I was preparing to create a compatibility guide, I noticed that the HTML code consisted of a table. While tables are effective for displaying data, they can be cumbersome to edit frequently. What tools are available to quickly and cleanly edit an exist ...

Transferring information from an online platform onto pre-arranged sheets for hard copy

Has anyone had success printing from a website? I have some papers that are already printed with checkboxes. These checkboxes need to be filled in based on information entered through a web form or retrieved from a MySQL database. All of this information ...

What is the best way to send a POST parameter using JavaScript?

Attempting to submit a variable and its name through a form, I had to change the button type to "button" instead of "submit" for additional validation purposes. Here is the updated button: <button type="button" onclick="subForm()" name="del" id="delet ...

Separately extract the input values from the divs

Here is a snippet of my HTML code: <div id="Section1" class="divFiles"> <input type="text" name="file"> <input type="text" name="file"> <input type="text" name="file"> <input type="text" name="file"> </div> < ...

Issue with CSS Dropdown menu not appearing in Internet Explorer 7

Having trouble getting my dropdown menu to display properly in Internet Explorer 7. In Firefox, everything works fine when hovering over the links under the Attorney Profile button, but not in IE7. CSS: http://pastebin.com/geCXmaz2 Visit the website here ...

Make sure link opens in the same window/tab

Currently, I am utilizing the Open Link in Same Tab extension on Google Chrome. This extension can be found here. The purpose of this extension is to ensure that all links open in the same window/tab, which is necessary for touch screen kiosk left/right s ...

Guide on attaching an event to every dynamically created element in JavaScript

I'm currently generating 'li' elements dynamically using a loop and running into issues when it comes to assigning events to each generated element. My goal is to assign an onclick event to every li element that is created. Check out the co ...

quickest method for accessing the selected radio button using jQuery

I'm trying to use jQuery to retrieve the selected radio button and display the text associated with that radio button. <div id="Poll"> <div id="PollQuestion">Your favorite color?</div> <ul> <li class="liAnsw ...

The width attribute is not being applied in Internet Explorer's compatibility modes

When I try to apply the following CSS, the width does not get applied in IE Compatibility modes: .multipleShipmentsGrid { border-color:#949EAA; border-style:solid; border-width:1px; width:80%!important; border-collapse:collapse; } How ...

Is there a way to create a submit button that also functions as a link?

I am currently working on a Quiz project where I need to include 25 questions. Each question will have its own HTML page with 4 radio buttons, a submit button, and a reset button. The goal is to have the user click the submit button to move to the next pag ...

Show off markdown formatting without the need for v-html

I run a unique type of platform that allows users to publish their own blog posts using a WYSIWYG editor, and then share them on the site. My top priority is to ensure security against XSS attacks, which is why I am looking for alternatives to using v-htm ...

Is it possible to trigger an A-Frame DOM/CSS/animation event based on video timestamps?

Is it possible to activate an event in A-Frame based on a specific time point of a video or audio file, without the need to interact with the video object directly? For example, changing the light or color properties of a nearby primitive? I am currently ...

Showcasing a pair of images adjacent to each other with adequate spacing using CSS

I'm having trouble displaying two images side by side on my website with a gap in between. I've used CSS to position the images next to each other. This is the HTML code I'm using: <div id="divCenter"> <img src="Company L ...

Enhance Your Forms with Bootstrap 4 Input Extension

I've been struggling to create a form with Bootstrap 4, specifically setting the value in an input text client-side for a modal form. No matter what I try, it just doesn't seem to work... Here is the form: $('#contact-modal').on(& ...

Preventing jQuery from matching multiple elements

I'm currently working on implementing a rollover effect using jQuery. I've encountered an issue due to the fact that I'm trying to execute a mouseover event on an object containing a link. The specific scenario involves a level-2 navigation ...

The process of masking a video with alpha data from another video on canvas seems to be experiencing a

I have a unique setup on my page where I'm masking one video with another. Essentially, when the Play button is pressed, a second video slowly appears over the looping video in the background. This effect is achieved by using a black/white mask transf ...