在3d立方体的选择边的模糊的文本

时间:2014-03-02 01:12:47

标签: css css3 transform css-transforms blurry

我正在尝试创建一个四面都有文字的立方体,但是在某些边上,文字看起来很模糊。快速谷歌搜索后,我发现添加-webkit-font-smoothing: subpixel-antialiased到包含元素修复了一些问题,但似乎没有为我修复它。第1和第2侧很漂亮,但剩下的4条边模糊不清。我真的很感激,如果有人能帮我解决这个问题。我把一个jsfiddle放在一起,代码如下。提前谢谢!

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);
}

1 个答案:

答案 0 :(得分:1)

Per this question,值得注意的是WebKit将文本解释为纹理,而不是矢量,后变换。因此,首先渲染的文本具有矢量渲染的优点,而后续的文本渲染则是纹理。

尝试放大字体,然后使用-webkit-transform:scale人为地减少字体。这基本上创造了更高分辨率的纹理。我不打算废话你,说我想出了这个解决方案(信用转到Duopixel),but I did update your fiddle。如果可能的话,尝试使用sans-serif字体,因为它们对于缩放问题比它们的serif朋友更具弹性(尽管这不一定是可靠的)。我在给你的例子中使用了Arial。以下是应用于标题的代码:

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

祝你好运!