IE leaves blank space on the Div conversion scale

I have a problem when I scale the div to fit it. This issue only appears in Internet Explorer. I tested only versions 9 and 11, but I am sure that it exists in others.

Whenever I scale the window down the div scale as they should. However, in Internet Explorer they leave this strange white space on the right. This seems to be happening inside #pageContent , and scaling up #formScale seems like a problem.

Does anyone have any ideas on why this might happen? Because I can’t figure it out for life.

note - I don't want to solve this by hiding overflow

JSFiddle | Full Screen JSFiddle

Here is an image showing a space when the IE 9 window shrinks: enter image description here

HTML

 <div id="pageContent"> <div id="formBox"> <div id="formScale"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> </div> </div> 

CSS

 #pageContent { width:100%; overflow:auto; padding-bottom:20px; border:1px solid red; } #formBox { display:block;height:auto; padding:15px 10px;border-bottom:5px solid red;} #formScale::after { display: block; content: ''; padding-bottom:5px; } #formScale { display:block; position:relative; width:940px; left:50%; margin-left:-470px; -webkit-transform-origin: top center; -moz-transform-origin: top center; transform-origin: top center; -ms-transform-origin: top center; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .box { height:1178px;width:940px;background-color:yellow;margin-bottom:10px; } 

Js

 resize(); zoomProject(); $(window).resize(function (e) { resize(); zoomProject(); }); function resize() { $("#pageContent").css('height', ($(window).height()-30) + 'px'); } function zoomProject() { var maxWidth = $("#formBox").width(), percent = maxWidth/930; $("#formScale").css({ 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')' }); } 
+7
javascript jquery css internet-explorer css3
source share
3 answers

I GOT

I changed the start of the conversion to the upper left, used the automatic fields on the trimSpace field to focus instead, and made a few changes to JavaScript. Works for me in IE.

I wrapped the formScale box in another div called trimSpace and set its width to the new width of the scaled elements. I hide the X overflow for this new div to trim the spaces. This div can still be larger than the pageContainer field, and the scrollbars are functional.

Here, check out this script: http://fiddle.jshell.net/bUY75/24/

HTML

 <div id="pageContent"> <div id="formBox"> <div class="trimSpace"> <div id="formScale"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> </div> </div> </div> 

Javascript

 zoomProject(); resize(); $(window).resize(function (e) { resize(); zoomProject(); }); function resize() { $("#pageContent").css('height', window.innerHeight - 60 + 'px'); } function zoomProject() { var maxWidth = $("#formBox").width(), percent = maxWidth / 930; $("#formScale").css({ 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')' }); $(".trimSpace").css('width', (930 * percent) + 'px'); $("#formBox, .trimSpace").css('height', ($("#formScale").height() * percent) + 'px'); } 

CSS

 #pageContent { width:100%; overflow:auto; padding-bottom:20px; border:1px solid red; } #formBox { display: block; position: relative; height: 100%; padding: 0; } #formScale::after { display: block; content:''; padding-bottom:5px; } #formScale { display:block; position:relative; width:940px; margin: 0; //This was the cause of the left whitespace /*left:50%;*/ /*margin-left:-480px;*/ -webkit-transform-origin: top left; -moz-transform-origin: top left; transform-origin: top left; -ms-transform-origin: top left; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .trimSpace { display: block; position: relative; margin: 0 auto; padding: 0; height: 100%; /*width: 100%;*/ overflow: hidden; } .box { height:1178px; width:940px; background-color:yellow; margin-bottom:10px; } 


Previous

This is because Internet Explorer does not scale the CSS width attribute when elements are converted in other browsers. The spaces you see are where the scaled elements were expanded before they were reduced in appearance. You do not need to completely disable overflow, only on a scaled element. It just removes the extra spaces without affecting the visibility of the content. I made a few changes to clear the demo. Here's a script for a demo: http://fiddle.jshell.net/bUY75/2/

and here is the code:

HTML

 <input type="range" name="percent" min="1" max="300" step="1" value="100" onchange="zoomProject(this.value)">&nbsp;Zoom (1 to 300%) <div id="pageContent"> <div id="formBox"> <div id="formScale"> <div class="box">test1<br><input type="text"></div> <div class="box">test2</div> <div class="box">test3</div> <div class="box">test4</div> </div> </div> </div> 

CSS

 #pageContent { width: 100%; overflow: auto; padding-bottom: 20px; border: 1px solid red; } #formBox { display: block; position: relative; height: 100%; padding: 0; } #formScale { display: block; position: relative; padding: 15px 10px; margin: 0; width: 100%; overflow-x: hidden; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; -webkit-transform-origin: top left; -moz-transform-origin: top left; transform-origin: top left; -ms-transform-origin: top left; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .box { height: 110px; background-color: yellow; margin-bottom: 10px; } .more-content { height: 400px; background-color: #2bde73; padding: 10px; font-size: 18px; color: white; margin-top: 20px; } 

Javascript

 var height = $("#formScale").height(); window.onload = function() { resize(); $(window).resize(function (e) { resize(); }); }; function resize() { $("#pageContent").css('height', window.innerHeight - 60 + 'px'); } function zoomProject(amount) { var maxWidth = $("#formBox").width(), percent = amount / 100; $("#formScale").css({ 'transform': 'scale(' + percent + ')', '-moz-transform': 'scale(' + percent + ')', '-webkit-transform': 'scale(' + percent + ')', '-ms-transform': 'scale(' + percent + ')' }); } 
+4
source share

When you transform an element, it is a bit like using position:relative . The element still occupies its original place in the document flow; it is simply rendered differently.

For these reasons, I would be inclined to say that the best question is why Chrome does not have this empty space? Technically, it should be!

To fix the problem, you can simply use overflow-x:hidden to remove horizontal scrolling from the container element. I know that you said you didn’t want, but this is the only solution I can think of.

+5
source share

Unfortunately, if you want to specifically configure IE, you may have to use IE CSS hacks. http://www.webdevout.net/css-hacks

http://dimox.net/personal-css-hacks-for-ie6-ie7-ie8/

-2
source share

All Articles