Fixing alignment and responsiveness problems with a hovering circle div

I have 3 circular divs that resize slightly when you hover over them, but this resizing also occurs if you hover near them. Additionally, I want them to be centered with some responsive spacing.

Here is a live demo: demo

Below is my code:

    <div id="kruhobal">
        <div class="kruh" id="kruh1"></div>
        <div class="kruh" id="kruh2"></div>
        <div class="kruh" id="kruh3"></div> 
    </div>

CSS:

#kruhobal
{
    width:100%;  
}

@media only screen and (max-width:111100px)
{
.kruh
{
    display: inline-block;
    transition: transform 1.0s ease;

}
.kruh:before
{
    border-radius:50%;
    content: '';
    display: inline-block;
    padding-bottom: 0vw;
    width: 13vw;
    height: 13vw;
}
.kruh:hover
{
    transform: scale(1.15);
}
#kruh1
{

}
#kruh1:before
{
    background:red;
    background-size:cover;  
}


#kruh2:before
{
    background:red;
    background-size:cover;      

}
#kruh3:before
{   
    background:red;
    background-size:cover;
}

Answer №1

It seems like the animation effect on your circles is being triggered even when the mouse is outside the circle. This is because the element itself is rendered as a square. To better understand this, try adding an outline to the elements in your original example.

The reason for the square rendering is due to the :before element being set as a square, causing the hover event to be activated by that element. One suggestion would be to remove the :before element completely and utilize the element itself, just like in the code snippet below:

.kruh {
  display: inline-block;
  border-radius: 50%;
  background:red;
  transition: transform 1.0s ease;
  height: 13vw;
  width: 13vw;
}
.kruh:hover {
  transform: scale(1.15);
 }
<div id="kruhobal">
  <div class="kruh" id="kruh1"></div>
  <div class="kruh" id="kruh2"></div>
  <div class="kruh" id="kruh3"></div>
</div>

If keeping the :before element is necessary, you can also apply the border-radius to the parent div as a solution.

In terms of centering the items and creating some "little responsive space," utilizing flexbox on the parent element would be ideal. Adding margin to each item will create the desired spacing between them.

 #kruhobal {
     display: flex;
     justify-content: center;
 }

.kruh {
  display: inline-block;
  border-radius: 50%;
  background:red;
  transition: transform 1.0s ease;
  height: 13vw;
  width: 13vw;
  margin: 0 5px;
}
.kruh:hover {
  transform: scale(1.15);
 }
<div id="kruhobal">
  <div class="kruh" id="kruh1"></div>
  <div class="kruh" id="kruh2"></div>
  <div class="kruh" id="kruh3"></div>
</div>

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

Bring to the front the div altered by a CSS3 animation

Recently, I encountered an issue with a div card that triggers an animation when clicked. The animation involves the card scaling up larger, but the problem arises as its edges get hidden under other cards. To visualize this, take a look at the screenshot ...

What is the method for ensuring that the delete functionality is displayed within the same row?

In my division, there are options for names and deletion. It is displayed on my website as: 1.jpg delete The HTML code for the division is: <div id="files1" class="files"> <b class='dataname' >1.jpg</b> <span cla ...

Not compatible with certain browsers, scrollable wrapper in fullscreen

I am looking to create a unique layout with a fullscreen div on top of a footer. The main element (#wrapper) should have a fullscreen background image and be scrollable to reveal the footer underneath. Check out my code on JSFiddle: https://jsfiddle.net/t ...

JSON parsing error within the HTML Sidebar list

I have a JSON file that contains data I need to parse in order to display information in my sidebar. When a user clicks the button labeled "List all sessions", the goal is to showcase all of the available session details grouped by Session ID and location. ...

How can you spot the conclusion of different lines that refuse to remain in place?

Currently, I am facing a jquery issue that has left me stumped. The website I am working on is structured as follows: <div class="Header"></div> <div class="main"><?php include('content.html'); ?></div> <div clas ...

Vue component always renders a new line

Whenever I include a <component> tag in my main application, it always renders on a new line. Is there a way to make it inline? I am trying to achieve something like this: <p>This is a component :<component></component></p> & ...

How to make a line stand out in an HTML table using <td> tag: **Bold a

I have written the code below to create a table, and I only want the text XYZ to be bold and all other text to remain unbold within the < td > tag. However, when I implemented this code, the entire < td > content became bold. I would prefer not ...

How can the edit feature be implemented in AngularJS?

I am struggling with implementing an edit field in AngularJS. Can someone please help me with this? Here is the code for my CRUD operations: var app = angular.module('myApp', []) app.controller('myCtrl', ['$scope', functio ...

Is there a method to access a website, trigger JavaScript functions, and subsequently retrieve the HTML content using PHP?

I am currently exploring options to access a webpage, execute JavaScript functions on it (thus altering the HTML content), and eventually save the modified version of the page. I'm uncertain if this approach is feasible, and if not, are there alternat ...

Ensure the child element is selected immediately following an h2 tag using HTML and CSS

Consider the following brief HTML snippet: <div ...> <h2 class="test">...</h2> <p>...</p> </div> Is it feasible to retrieve the child element (p in this case) after the h2? I have been contemplating poten ...

Mastering the Art of Manipulating Z-Index Stacking Context in CSS Using Transforms

I'm struggling to position the red square on top of the table. After reading articles about Z-index Stacking Context and browsing through this stack overflow page about overriding CSS Z-Index Stacking Context, I still can't seem to figure it out. ...

jQuery puzzle: a form within a form within a form

I am facing a bit of a dilemma with a partially working solution. The scenario is this - I am using a basic .load() function attached to a <select> element to fetch another form populated through PHP/MySQL. What I intend to achieve is for this newly ...

Having trouble with Simplehtmldom's innertext function?

While working with simple_html_dom: I encountered the following code snippet: $j = ' <itemBody> <div>films - to watch (Simple Present)<br/> <textEntryInteraction responseIdentifier="RESPONSE_1"/> ...

What is the best way to overlay elements with a gray background?

Here is a snapshot of the local web page: [defective image deleted] This is what the deployed webpage looks like on Vercel: The issue is that the gray div is revealing its underlying elements. .zoombackground { background-color: #333; left: 0; ...

A guide on showing an image encoded in base64 within an HTML document

I obtained the image URL and proceeded to download the image which was then converted into base 64 using an online converter. Here is the base 64 code: iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d... Can I now utilize this large size im ...

Are you able to develop a customized TestNG Listener to cater to your specific requirements?

I have developed a unique concept for a TestNG listener that meets my specific requirements. Essentially, I aim to design a custom listener that generates a report using a predefined HTML format. The crux of my idea revolves around declaring the listener ...

What could be the reason for justify-self: flex-start not positioning the div at the bottom of a column?

I want to display a div in three levels: header, content, and footer. The content can vary in height and the footer should always be at the bottom. Here is how I have implemented it: <div class="news-content-block"> <div class=" ...

Is there a bug in IE9 with CSS precedence?

Two CSS rules are in place: .avo-lime-table th, .avo-lime-table td { background-color: grey; } Next rule: .avo-lime { background-color: green; } All is functioning correctly in FireFox, Chrome, Opera and Safari. However, as usual, Microsoft&apos ...

Click the link to capture the ID and store it in a variable

Currently working on a project involving HTML and JavaScript. Two HTML pages ("people.html" and "profile.html") are being used along with one JavaScript file ("people.js") that contains an object with a list of names, each assigned a unique ID: var person ...

Decreasing the space between columns in Bootstrap 3

My objective is: However, the current layout appears like this (the issue isn't the bottom margins, I've already decided they should be smaller): The problem lies in the gutter size which is determined by padding, as indicated by the grey area ...