What is the best way to adjust the padding during a scaling transformation?

Currently, I am working on a scaling transform where the origin is centered horizontally. However, I have noticed that when I scale the element, the vertical padding appears to be scaled, but the horizontal padding remains unchanged. How can I ensure that the horizontal padding scales proportionally as well?

.inner {
  margin: 0 auto;
  width: 300px;
  height: 300px;
  background-color: #f99;
  transform: scale(1.5);
  transform-origin: top center;
  box-sizing: border-box;
  padding: 20px;
}

.inner2 {
  background-color: #99f;
  height: 260px;
}

.outer {
  background-color: #ccc;
}
<div class="outer">
  <div class="inner">
    <div class="inner2">
    </div>
  </div>
</div>

Another query I have is related to Chrome dev tools. I have noticed that the Chrome dev tools do not update the computed properties after the scaling transform, such as the width remaining unchanged in the inspector.

Additionally, I am facing an issue where the inner element extends beyond the outer element after the scaling transform. How can I adjust this so that the outer element fully contains the inner element?

UPDATE: By eliminating a border on the inner element, per the suggestion from @Stickers, I can clearly see that the horizontal padding is not scaling, unlike the vertical padding.

UPDATE: For a demonstration of the scaling behavior, you can check out this codepen with a larger padding showcasing the difference in scaling between vertical and horizontal padding.

Answer №1

With the .inner element having the property box-sizing: border-box; defined, the browser will adjust the width and height values to consider any border and padding.

By calculating 300-20x2-2x2=256 (height-paddingx2-borderx2), we find that the .inner2 should ideally have a height: 256px instead of height: 260px; for a perfect fit. Correcting this will ensure that all padding values scale correctly in relation to the height.

Refer to the specifications for determining the size of the .outer elements:

3. The Transform Rendering Model

Keep in mind: Transformations impact visual rendering, but do not alter the CSS layout except for overflow adjustments...

This should also address any concerns related to DevTools configuration.

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

How to deselect a checkbox in next.js when another one is selected

I'm looking to create a navigation system where clicking on a button scrolls to a specific section. However, I'm wondering how to deselect three inputs when one is selected in next.js using the code below. Do I need to modify each menu item indiv ...

Working towards ensuring my website is responsive

Hello, I am a CSS beginner currently working as an intern. My task is to make a website's CSS compatible with Internet Explorer, and then make it responsive and scalable. Essentially, the design should retain its appearance when the window size change ...

Utilizing CSS to create a text box with angled left and right edges

.soccer-field{ width: 50%; box-shadow: 0 4px 12px 4px rgba(0,0,0,0.2); } .text-sf p{ float:left; } .right-curve{ float:right; width: 0; height: 0; border-style: solid; ...

The CSS :not selector does not work as intended

My goal is to assign the class no-color to a specific tag. When JavaScript is enabled, I want this class to be removed and the text to be colorized. However, my current CSS solution is not working as expected. Below is a sample code snippet demonstrating t ...

When clicking, the fixed header and footer suddenly shift out of place

In my jquery mobile application, I am facing an issue with a fixed header and footer. Whenever I click on the screen, the fixed header and footer get displaced and are no longer fixed. I am unsure how to resolve this bug. Any suggestions on how to fix it w ...

What impact do varying screen sizes have on the width of CSS?

Can someone explain what this CSS code actually does: .class { width: 800px; } I've noticed that on my laptop screen, the element appears to be exactly 800 pixels wide. However, when I view it on my tablet screen, it shows up as 1600 pixels wide. Th ...

Corner of the Border Revealing a Clear Sky above

Looking to enhance my navigation bar (menu) by adding a cornered border when the user hovers over it. <nav> <a href="#home">Home</a> | <a href="#about">About</a> | <a href="#blog">Blog</a ...

Custom Bootstrap 3 Panel Organization

I'm intrigued by the layout shown in the image attached. My attempts to recreate it using a combination of columns and rows have been unsuccessful. Could it be that I'm going about this the wrong way? ...

What is the best way to display value in a dropdown option field using Laravel?

I am currently working with 3 tables: hosts, visitors, and visitor_types. My objective is to display the host name and visitor type in a drop-down option button. However, I find myself a bit perplexed when it comes to the controller and route code. I have ...

Utilizing a combination of jQuery and JavaScript, construct an innovative image slider to meet

I'm working on creating a slider that allows users to navigate through reviews by clicking arrows, moving from review1 to review2 and so on. I've set up my HTML with the reviews and my CSS with hidden values for now. Any assistance would be great ...

Can we make one tab disappear when another tab is clicked in Ionic 2 app menu icon?

I am working on a project using Ionic 2 and I have implemented multiple tabs in the application. However, I need to find a way to hide the top tab when the user clicks on the bottom tabs menu icon. Here is my Plunker for your reference. My goal is to ma ...

My Javascript file is not being recognized by MVC

Initially, I created an MVC application without fully understanding that MVC is more backend-oriented than frontend-focused. I ended up building a simple website with just HTML, CSS, and Javascript files, which worked perfectly. However, when I tried to in ...

Stretchable navigation cell

I am working on a navigation bar called "nav" that consists of a "ul" and "li". I have specified the display property for the "ul" as table and for the "li" as table-cell. Setting the "ul" to take up the full width of the wrapper ensures proper alignment. ...

What is the best way to incorporate tooltips in SVG?

My teacher wants me to display a tooltip on an SVG circle with links and information when we hover over it. They suggested using jQuery UI, but I've done extensive research and nothing has been able to assist me so far. ...

challenges with positioning div elements using relative CSS styling

This is a section of my code: CSS : .body .left, .right { position:relative; z-index:6; display:inline-block; } .body .left { top:0; left:0; width:100px; height:300px; margin-right:10px; borde ...

Unable to locate the element with the specified id: <path>

I am aiming to dynamically change the fill attribute of a specific <path> element when a page loads. Here is the detailed information about the path element: <path xmlns="http://www.w3.org/2000/svg" style="fill:#ff0000;stroke:#000000;stroke-wid ...

Need jQuery solution for changing CSS in numerous locations upon hover

Currently, I am working on a WordPress website and I am trying to figure out how to change the CSS color of a side navigation element when a remote image is hovered over. In a typical scenario, I would accomplish this using CSS by assigning a hover class ...

What could be causing the malfunction in this positioning and display?

<article id="l1"> <img class="active_pic" id="a1" src="img/load.gif"/> </article> <article id="l2"> <img class="active_pic" id="a2" src="img/load.gif"/> </article> <article id="l3"> <img class="activ ...

"Maximizing Bootstrap Functionality with Angular 2: Step-by

I'm experiencing an issue with Angular2, Bootstrap 3.3.7, and Bootstrap Plugins. I have imported all the necessary stylesheets and JavaScript files in the 'index.html' file. Below is the snippet from the index.html: <!-- Bootstrap & ...

Hide the paragraph element when the navigation link is being hovered over

Is there a way to hide a <p> element when hovering over a link? My website is built with Drupal and uses the Superfish module for the navigation bar. When I hover over the links, a secondary nav bar drops down. I want the slogan of the website to di ...