4

I have a div which has two child div's, one div on the screen plan and other vertically perpendicular to the screen.

I try to rotate the div along Y axis for about 30 degrees. keeping its transform-style 3d preserved.

When doing it, in Firefox the border isn't a straight line anymore. It looks like this

This is the whole div

For closer view

Closer view

I happen to use the following code

.holder {
  position: relative;
  top: 0;
  left: 0;
  width: 200px;
  height: 226px;
  perspective: 2000px;
  -moz-perspective: 2000px;
}

.box {
  position: absolute;
  left: 0;
  top: 0;
  width: 200px;
  height: 226px;
  background-color: transparent;

  transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;

  transform: translateZ( -100px ) rotateY(30deg);
  -moz-transform: translateZ( -100px ) rotateY(30deg);

  transition: transform 0.5s;
  -moz-transition: transform 0.5s;
}

.box div {
  position: absolute;
  margin: 0;
  display: block;
 }

.box .front {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;

    transform: rotateX(0deg) translateZ(10px);
    -moz-transform: rotateX(0deg) translateZ(10px);

    background-color: grey;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.box .left {
    left: 0;
    top: 0;
    bottom: 0;
    width: 20px;

    transform: rotateY(-90deg) translateZ(10px);
    -moz-transform: rotateY(-90deg) translateZ(10px);

    background-color: black;
    background-size: cover;
    background-position: left;
    background-repeat: no-repeat;
}
<div class="holder">
  <div class="box">
    <div class="front"></div>
    <div class="left"></div>
  </div>
</div>

Please let me know if I'm missing anything.

Picture of the link provided in one of the answers : enter image description here

Presse
  • 418
  • 1
  • 4
  • 23
  • 2
    Hope you've searched before posting it as a question as here already available one. [**Please look into this**](http://stackoverflow.com/questions/9235342/3d-css-transform-jagged-edges-in-firefox) this would help you, as most of already posted it as an answer, LoL ;) – vivekkupadhyay Sep 10 '15 at 12:48
  • Good find @vivekkupadhyay. As this is a well known problem, I didn't bother searching for an existing question. I am marking this as a dupe right away. – Abhitalks Sep 10 '15 at 12:56
  • I found the question, yet the answers provided doesn't seem to solve my problem. – Presse Sep 10 '15 at 13:00
  • @vivekkupadhyay Can you have a look at this problem once again, as the answers provided in your link isn't working either. – Presse Sep 10 '15 at 14:30
  • @Presse your given link in the que is working perfectly fine on my end, which browser version are you using ? – vivekkupadhyay Sep 11 '15 at 03:49
  • @vivekkupadhyay Firefox version 40.0.3 and OS - OS X Yosemite Version 10.10.4 – Presse Sep 11 '15 at 05:24
  • @Presse I've checked on 41.0(normal) and 42.0(Developer Edition) and its working fine, windows 8.1 – vivekkupadhyay Sep 11 '15 at 05:37
  • @vivekkupadhyay Is there any other possible workarounds that I could try? – Presse Sep 11 '15 at 05:44
  • @Presse it looks good (no pixel steps) in firefox 40.0.3 and windows 7 – Lucian Depold Sep 14 '15 at 07:32
  • @LucianDepold Even I checked in windows. It seems like the problem is appearing with Ubuntu and Mac systems. – Presse Sep 14 '15 at 08:14
  • did you test on those systems directly or did you use something that simulates them ? maybe the simulation causes the trouble. You should add the linux aspect to your question. – Lucian Depold Sep 14 '15 at 08:17
  • No I'm using the system directly. No Emulators. Sure will do. – Presse Sep 14 '15 at 08:34

3 Answers3

4

It's a Firefox aliasing problem, you can add

outline: 1px solid transparent;

as a workaround to .box .front.

aghidini
  • 2,855
  • 5
  • 29
  • 32
  • I just clicked the fiddle you posted, it still looks the same. I'll update the picture in the question for your reference – Presse Sep 10 '15 at 12:56
2

I got a work around for your issue reference.

Try filter for the div having class="box".

Basically this is used for svg elements but it is working for your case as well.

filter: url('data:image/svg+xml;utf8,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><filter id="gaussian_blur"><feGaussianBlur in="SourceGraphic" stdDeviation="0" /></filter></defs></svg>#gaussian_blur');

Tested in latest version of Opera, FF and Chrome for both mac and windows.

Working Demo here

Shrinivas Pai
  • 7,491
  • 4
  • 29
  • 56
1

I'm not sure why using translateZ inside a transformed element is not works properly on FF.

Adding outline: 1px solid transparent; is not working, but adding border: 1px solid transparent; to the .box will working, with removing transform: rotateX(0deg) translateZ(10px); from the .box .front.

Example:

.holder {
  position: relative;
  top: 0;
  left: 0;
  width: 200px;
  height: 226px;
  perspective: 2000px;
  -moz-perspective: 2000px;
}

.box {
  position: absolute;
  left: 0;
  top: 0;
  width: 200px;
  height: 226px;
  background-color: transparent;

  border: 1px solid transparent;

  transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;

  transform: translateZ( -100px ) rotateY(30deg);
  -moz-transform: translateZ( -100px ) rotateY(30deg);

  transition: transform 0.5s;
  -moz-transition: transform 0.5s;
}

.box div {
  position: absolute;
  margin: 0;
  display: block;
 }

.box .front {
    left: 0;
    right: -4px;
    top: 0;
    bottom: 0;

    /* transform: rotateX(0deg) translateZ(10px); */
    /* -moz-transform: rotateX(0deg) translateZ(10px); */

    background-color: grey;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.box .left {
    left: 0;
    top: 0;
    bottom: 0;
    width: 20px;

    transform: rotateY(-90deg) translateZ(10px);
    -moz-transform: rotateY(-90deg) translateZ(10px);

    background-color: black;
    background-size: cover;
    background-position: left;
    background-repeat: no-repeat;
}
<div class="holder">
  <div class="box">
    <div class="front"></div>
    <div class="left"></div>
  </div>
</div>