Centered div's overflow remains visible

Yes, the positioning of the parent container is set to relative.

I am attempting to achieve a ripple effect by expanding multiple circles from a central point in all directions until they stretch beyond the viewport.

I have created circular divs that are absolutely positioned and centered on the screen. Upon clicking on them, a new class called grow is added which increases their width and height to trigger the expansion effect. However, I'm facing an issue where the x-overflow isn't hidden when the circles expand beyond the viewport boundaries.

Notably, once a circle reaches the left edge of the viewport, it continues to expand in other directions but seems unable to cross the boundary of the window's edge.

<body>
  <div class="circle"></div>
</body>
body {
  position: relative;
}

.circle {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid #000;
  border-radius: 1000px;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  transition: all 1s ease-in-out;
  overflow: hidden;
}

.grow {
  border: 1px solid #000;
  width: 2000px;
  height: 2000px;
}
$(".circle").click(function() {
  $(this).addClass("grow");
});

Answer №1

When absolutely-positioned elements are larger than the viewport, they may not be centered relative to their own size if you set 'top', 'right', 'bottom', and 'left' all to zero. To achieve centering relative to its own size, you must set the element to be in the center of its parent container and apply overflow: hidden on the parent. One method is to use left: set to 50%, then adjust margin-left: to half of the element's size. Here is an example:

body {
  overflow: hidden;
}
.circle {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid #000;
  border-radius: 1000px;
  margin: 0 auto;
  left: 50%;
  margin-left: -5px;
  transition: all 1s ease-in-out;
}

.grow {
  border: 1px solid #000;
  width: 2000px;
  height: 2000px;
  margin-left: -1000px;
}

This code snippet should address your concern. Feel free to check out this CodePen for reference.

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

Facing an issue where the CSS class name is not displaying correctly when utilizing CSS Modules with my React

This webpack.config.js file is dedicated to the module section, where loaders are defined for JSX files and CSS. module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'bab ...

Executing npm run build index.html results in a blank page being generated without any error messages or warnings

After building my react app with npm run build, I encountered a problem where clicking on index.html resulted in a blank page opening in the web browser. I explored several solutions to address this issue but none seemed to work. Some of the strategies I ...

Changing the style of Vuetify v-list-item when hovering over it

I just started using Vuetify and I came across a v-list sample that I need help with. Here is the link to the Vuetify v-list sample on Github. My v-list: https://i.sstatic.net/ykTIi.jpg Code: <template> <v-card max-width="500" class= ...

What is the reason for the countdown number's color remaining the same even after it reaches a specific time threshold?

Creating a simple countdown for sports was my idea, but now I'm stuck on the "changeColor" part that I don't have enough knowledge about. The countdown is functioning perfectly, but customizing the colors and adding CSS animations seems challeng ...

What is the best way to center a heading element within a section on a webpage?

I need assistance aligning the h1 element with the specific class wish to the center of its section, both horizontally and vertically. Unfortunately, I have been unable to achieve this thus far. Any guidance would be greatly appreciated. Below you will fi ...

The website code lacks a dynamically generated <div> element

When using jQuery to dynamically add content to a "div" element, the content is visible in the DOM but not in the view page source. For example: <div id="pdf"></div> $("#btn").click(function(){ $("#pdf").html("ffff"); }); How can I ensur ...

Is Firefox the only browser where the webpage is displayed off-center?

I've encountered a strange issue with my website that I can't seem to figure out. Despite searching extensively on Google and Stackoverflow, I haven't come across anyone else facing the same problem. During testing in different browsers lik ...

Generate HTML content using AngularJS

Is there a way to format a string as HTML when using it in the following syntax: <div> {{ text }} </div> Instead of displaying the actual HTML, only the text is shown - for example " ab " ...

Removing a Dynamic Element in ReactJS

--CustomFieldSection.js-- import React, { Component } from 'react'; import CustomField from './CustomField.js'; class CustomFieldSection extends Component{ constructor(props){ super(props); this.stat ...

Why is this element occupying an excessive amount of space horizontally?

I've been diligently working on a unique custom WordPress theme as part of a school project. Our task is to redesign the homepage of an association, in my case, a theater group. One of the challenges I encountered was customizing the WordPress menu t ...

Error: Uncaught TypeError - The function indexOf is not defined for e.target.className at the mouseup event in HTMLDocument (translator.js:433) within the angular

Upon clicking on an SVG to edit my data in a modal bootstrap, I encountered the following error: Uncaught TypeError: e.target.className.indexOf is not a function at HTMLDocument.mouseup (translator.js:433) This is my SVG code: <svg data-dismiss ...

Angular's ng-disabled feature seems to be experiencing a delay in functionality

While editing the file, I have the ability to modify the filename and add additional files for versions. Once a file has been chosen, the filename edit field should be disabled immediately. Despite attempting the following code, the field remains enabled u ...

Utilizing Selenium for the Upload of an APK Document

I've encountered an issue during my test. I'm attempting to upload an APK file, but the process seems to halt at that stage. My attempts with simple sendKeys using the file path and an AutoIT script have both proven unsuccessful. Below is my in ...

What is the most effective way to incorporate the Google Analytics script into a Django project?

Is it recommended to add the Google Analytics script directly in <script> tag and push it to GitHub, or should it be kept secret by adding it to the .env file and called in? When I attempted the second method, it appeared in the source page as is an ...

Modify inline BODY width using PHP

My PHP script fetches HTML content as a string, and sometimes it includes code with an inline width on the BODY tag. When this width is set to 100%, it disrupts some additional processing that takes place. I'm hesitant to apply an external style sinc ...

Tips for seamlessly placing a div with a background image within a parent container, all while preventing any scrolling issues as the child div rotates

I created a simple demo featuring a square image with rounded corners to give it a circular appearance. The image rotates slowly, but as it moves diagonally, the horizontal width fluctuates, causing the parent container to resize. I want the parent contain ...

Issues with custom logo and menu/sidebar toggle on Wordpress

Hello everyone, I am currently facing some difficulties with my new WordPress blog that utilizes the Skilt-Theme. Specifically, I'm having trouble with the custom-logo and sidebar-toggle features. When there is no logo present, you can see the layout ...

The scrolling action triggered by el.scrollIntoViewIfNeeded() goes way past the top boundary

el.scrollIntoViewIfNeeded() function is used to scroll to element el if it's not within the visible browser area. Although it generally works well, I have encountered some issues when trying to use it with a fixed header. I have provided an example s ...

Combining Three.js with iFrame for a mix of WebGL and CSS3D

After some experimentation, I successfully created a dynamic page that seamlessly integrates WebGL and CSS3D (with valuable guidance from this helpful SO post). To add an extra touch, I included an iframe: However, I noticed that the functionality to inte ...

Steps for preventing a button from being enabled until all mandatory fields are completed

Is it possible to have a button disabled until all required fields are filled out, with the button appearing grey in a disabled state and changing color when all fields are completed? I am facing an issue where clicking on the previous button is causing ...