Frage

I am trying to create a cube with text on all sides, however on some of the sides the text appears blurry. After a quick google search I found that adding -webkit-font-smoothing: subpixel-antialiased to the containing element fixed the problem for some but did not seem to fix it for me. side 1 and 2 are nice and clear, but the remaining 4 sides are blurry. I would really appreciate if anyone can help me figure this one out.. I put together a jsfiddle and also the code is below. Thanks in advance!

fiddle

HTML:

<div id="options">
  <ul id="nav">
    <li id="front" class="show-front">Show 1</li>
    <li id="back" class="show-back">Show 2</li>
    <li id="right" class="show-right">Show 3</li>
    <li id="left" class="show-left">Show 4</li>
    <li id="top" class="show-top">Show 5</li>
    <li id="bottom" class="show-bottom">Show 6</li>
  <ul>
</div>

<div class="container">
  <div id="cube" class="show-right">
    <div class="side front"><h2>This is side 1</h2></div>
      <div class="side back"><h2>This is side 2</h2></div>
      <div class="side right"><h2>This is side 3</h2></div>
      <div class="side left"><h2>This is side 4</h2></div>
      <div class="side top"><h2>This is side 5</h2></div>
      <div class="side bottom"><h2>This is side 6</h2></div>
    </div>
  </div>

CSS:

#nav {
    list-style: none;
}
#nav li:hover {
    cursor: pointer;
}
.container {
    width: 600px;
    height: 600px;
    position: relative;
    margin: 1em 1em 1em 2em;
    float: left;
    -webkit-perspective: 1000px;
    -moz-perspective: 1000px;
    -ms-perspective: 1000px;
    -o-perspective: 1000px;
    perspective: 1000px;
}

.container #cube {
    width: 100%;
    height: 100%;
    position: absolute;
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    -ms-transform-style: preserve-3d;
    -o-transform-style: preserve-3d;
    transform-style: preserve-3d;
    -webkit-transition: -webkit-transform 1s;
    -moz-transition: -moz-transform 1s;
    -ms-transition: -ms-transform 1s;
    -o-transition: -o-transform 1s;
    transition: transform 1s
}

.container #cube .side {
    background: black;
    margin: 0px;
    display: block;
    position: absolute;
    width: 596px;
    height: 596px;
    color: white;
    border-radius: 5px;
    box-shadow: 0 0 15px black;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    -ms-backface-visibility: hidden;
    -o-backface-visibility: hidden;
    backface-visibility: hidden;
}

.container #cube .front {
    -webkit-transform: translateZ(300px);
    -moz-transform: translateZ(300px);
    -ms-transform: translateZ(300px);
    -o-transform: translateZ(300px);
    transform: translateZ(300px);
}

.container #cube .back {
    -webkit-transform: rotateX(-180deg) translateZ(300px);
    -moz-transform: rotateX(-180deg) translateZ(300px);
    -ms-transform: rotateX(-180deg) translateZ(300px);
    -o-transform: rotateX(-180deg) translateZ(300px);
    transform: rotateX(-180deg) translateZ(300px);
}

.container #cube .right {
    -webkit-transform:rotateY(90deg) translateZ(300px);
    -moz-transform:rotateY(90deg) translateZ(300px);
    -ms-transform:rotateY(90deg) translateZ(300px);
    -o-transform:rotateY(90deg) translateZ(300px);
    transform:rotateY(90deg) translateZ(300px);
}

.container #cube .left {
    -webkit-transform: rotateY(-90deg) translateZ(300px);
    -moz-transform: rotateY(-90deg) translateZ(300px);
    -ms-transform: rotateY(-90deg) translateZ(300px);
    -o-transform: rotateY(-90deg) translateZ(300px);
    transform: rotateY(-90deg) translateZ(300px);
}

.container #cube .top {
    -webkit-transform: rotateX(90deg) translateZ(300px);
    -moz-transform: rotateX(90deg) translateZ(300px);
    -ms-transform: rotateX(90deg) translateZ(300px);
    -o-transform: rotateX(90deg) translateZ(300px);
    transform: rotateX(90deg) translateZ(300px);
}

.container #cube .bottom {
    -webkit-transform: rotateX(-90deg) translateZ(300px);
    -moz-transform: rotateX(-90deg) translateZ(300px);
    -ms-transform: rotateX(-90deg) translateZ(300px);
    -o-transform: rotateX(-90deg) translateZ(300px);
    transform: rotateX(-90deg) translateZ(300px);
}

.container #cube.show-front {
    -webkit-transform: translateZ(-300px);
    -moz-transform: translateZ(-300px);
    -ms-transform: translateZ(-300px);
    -o-transform: translateZ(-300px);
    transform: translateZ(-300px);
}

.container #cube.show-back {
    -webkit-transform: translateZ(-300px) rotateX(-180deg);
    -moz-transform: translateZ(-300px) rotateX(-180deg);
    -ms-transform: translateZ(-300px) rotateX(-180deg);
    -o-transform: translateZ(-300px) rotateX(-180deg);
    transform: translateZ(-300px) rotateX(-180deg);
}

.container #cube.show-right {
    -webkit-transform: translateZ(-300px) rotateY(-90deg);
    -moz-transform: translateZ(-300px) rotateY(-90deg);
    -ms-transform: translateZ(-300px) rotateY(-90deg);
    -o-transform: translateZ(-300px) rotateY(-90deg);
    transform: translateZ(-300px) rotateY(-90deg);
}

.container #cube.show-left {
    -webkit-transform: translateZ(-300px) rotateY(90deg);
    -moz-transform: translateZ(-300px) rotateY(90deg);
    -ms-transform: translateZ(-300px) rotateY(90deg);
    -o-transform: translateZ(-300px) rotateY(90deg);
    transform: translateZ(-300px) rotateY(90deg);
}

.container #cube.show-top {
    -webkit-transform: translateZ(-300px) rotateX(-90deg);
    -moz-transform: translateZ(-300px) rotateX(-90deg);
    -ms-transform: translateZ(-300px) rotateX(-90deg);
    -o-transform: translateZ(-300px) rotateX(-90deg);
    transform: translateZ(-300px) rotateX(-90deg);
}

.container #cube.show-bottom {
    -webkit-transform: translateZ(-300px) rotateX(90deg);
    -moz-transform: translateZ(-300px) rotateX(90deg);
    -ms-transform: translateZ(-300px) rotateX(90deg);
    -o-transform: translateZ(-300px) rotateX(90deg);
    transform: translateZ(-300px) rotateX(90deg);
}
War es hilfreich?

Lösung

Per this question, the interesting thing to note is that WebKit interprets your text as a texture, versus a vector, post-transform. Hence, the text which is rendered first has the advantage of vector rendering, whereas subsequent text renderings are as textures.

Try enlarging the font then artificially diminishing it using -webkit-transform: scale. This essentially creates a higher-res texture. I'm not going to bullshit you and say I came up with this solution (credit goes to Duopixel), but I did update your fiddle. If possible, try to use a sans-serif font, as they tend to be more resilient to scaling issues than their serif friends (though this isn't necessarily reliable). I've used Arial in the example I gave you. Here's the code, applied to your headers:

h2 {
    font-family: 'Arial';
    font-size: 120px;
    font-weight: 100;
    text-align: center;
    -webkit-transform: scale(.5);
}

Best of luck!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top