11

I've used the following css in various places on my site:

http://jsfiddle.net/uycq29mt/1/

.a { position:absolute; background:red; width:600px; height:100px; left:50%; transform: translate(-50%); } 

When run in internet explorer, you'll notice a horizontal scrollbar that appears to ignore the transform regarding the total width of the page.

2
  • I work on the IE team and filed a bug on this behavior recently. Additionally, I tweeted for sites that were affected by this bug, in an attempt to understand the impact this bug has had. Do you have a live site that is impacted by this? If so, it will help us understand the urgency for a fix. Commented Jan 16, 2015 at 18:32
  • Unfortunately it's not live yet, however the jsfiddle clearly demonstrates it. Commented Jan 19, 2015 at 18:13

1 Answer 1

16

There is a simple solution:

http://jsfiddle.net/uycq29mt/2/

.a { position:absolute; background:red; width:600px; height:100px; right:50%; transform: translate(50%); } 

Instead of sending the element left 50% (rightwards) and using a transform to send it left, I do the exact opposite. I never considered it until now but if you position an element to the extreme left, it won't affect the page width or the scrollbar.

Strangely, if you do the vertical equivalent of centering, by using top 50% and translate(0px, -50%) it does not appear to affect the vertical scroll bar.

It appears only Internet Explorer doesn't recalculate horizontal boundaries when transforms are used in this way. Pretty annoying. IE sucks.

Sign up to request clarification or add additional context in comments.

1 Comment

I've encountered this problem with vertical centering as well actually, which is what brought me here - jsfiddle.net/uycq29mt/12 The same solution appears to work there though - jsfiddle.net/uycq29mt/13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.