对于任何感兴趣的人,这是我的临时解决方案:现场演示。
我使用了这个精灵图像:
html:
<div class="container">
<h2 class="sub-heading"><span class="sub-heading-txt">Short title</span></h2>
</div>
<div class="container">
<h2 class="sub-heading"><span class="sub-heading-txt">A bit longer title</span></h2>
</div>
<div class="container">
<h2 class="sub-heading"><span class="sub-heading-txt">A damn long title is here!</span></h2>
</div>
(.container
只有变体需要 div)
CSS:
.sub-heading, .sub-heading:after, .sub-heading:before {
background:url(tha-sprite-url.png) 0 0 no-repeat;
}
.sub-heading {
position:relative;
display:inline-block; clear:both;
margin-left:31px; padding:0 18px 10px 0;
font-size:25px; font-weight:normal; color:#FFF; line-height:47px;
background-position:0 -75px;
background-size:100% 282px; /* the sprite's height */
}
.sub-heading:before, .sub-heading:after { content:" "; position:absolute; top:0; }
.sub-heading:before { left:-31px; width:31px; height:57px; }
.sub-heading:after { right:-12px; width:12px; height:42px; background-position:-150px 0; }
.sub-heading-txt {
display:block;
-webkit-transform:rotate(-2deg); -ms-transform:rotate(-2deg); transform:rotate(-2deg);
}
/* variations */
.container { margin-bottom:10px; }
.container:nth-child(3n+2) .sub-heading { background-position:0 -150px; }
.container:nth-child(3n+2) .sub-heading:before { background-position:-50px 0; }
.container:nth-child(3n+2) .sub-heading:after { background-position:-175px 0; }
.container:nth-child(3n+3) .sub-heading { background-position:0 -225px; }
.container:nth-child(3n+3) .sub-heading:before { background-position:-100px 0; }
.container:nth-child(3n+3) .sub-heading:after { background-position:-200px 0; }
适用于 IE9+
不幸的是,background-size
属性不支持“继承”值,因此必须在 css 中设置实际精灵的高度 :-( 我仍在寻找更有效的解决方案。