2017-03-16 21 views
0

客户端通过设计文件发送了部分文本在图像上,并且文本的背景在图像上具有“相乘”叠加层。但是,文本保持稳定的白色。文本背景颜色叠加在另一图像上复制,但文本保持纯白色

当文本只有一行时,我能够实现这一点 - 为背景(使用mix-blend-mode: multiply)和文本创建单独的容器,将它们的宽度与jQuery动态匹配,并将它们的绝对位置进行匹配。然而,有这样的文本是动态的,可以从1到多行。

我在我的智慧结束...任何帮助/想法/建议将不胜感激。谢谢!

example

FYI任何人想知道为什么不使用RGBA或不透明,这里的区别: multiply rgba/opacity

if($(".transparent_blue").length) { 
 
    var h3width1 = $(".transparent_blue+h3").innerWidth(); 
 
    bgwidth1 = h3width1 + 50; 
 
    $(".transparent_blue").width(bgwidth1); 
 
}
.top-content { 
 
    position: relative; 
 
} 
 
.text-wrap { 
 
    background-color: white; 
 
    width: 40%; 
 
    float: left; 
 
} 
 
.image-wrap { 
 
    height: 400px; 
 
    width: 60%; 
 
    float: right; 
 
    min-height: 450px; 
 
} 
 
.transparent_blue { 
 
    position: absolute; 
 
    z-index: 1; 
 
    margin-left: -20px; 
 
    background-color: #0067a3; 
 
    mix-blend-mode: multiply; 
 
} 
 
.transparent_blue_placeholder { 
 
    width: 1px; 
 
    height: 40px; 
 
} 
 
h2 { 
 
    text-transform: uppercase; 
 
    font-family: arial; 
 
    font-size: 2.7rem; 
 
    margin-top: 30px; 
 
    margin-bottom: 30px; 
 
} 
 
h3 { 
 
    font-family: arial; 
 
    position: absolute; 
 
    z-index: 2; 
 
    font-size: 1.3rem; 
 
    line-height: 2; 
 
    color: white; 
 
    margin: 0; 
 
    margin-left: -25px; 
 
    padding: 0 25px; 
 
} 
 
.h3-placeholder { 
 
    height: 80px; 
 
    width: 1px; 
 
} 
 
.image-container { 
 
    width: 100%; 
 
    height: 100%; 
 
    background: url("http://eskipaper.com/images/free-street-wallpaper-1.jpg") center center no-repeat; 
 
    background-size: cover; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="top-container"> 
 
    <div class="text-wrap"> 
 
    <h2>the ipsum</h2> 
 
    <div class="transparent_blue"> 
 
     <div class="transparent_blue_placeholder"> 
 
     </div> 
 
    </div> 
 
    <h3>At vero eos et accusamus et iusto odio dignissimos</h3> 
 
    <div class="h3-placeholder"></div> 
 
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 
 
    <h4>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</h4> 
 
    </div> 
 
    <div class="image-wrap"> 
 
    <div class="image-container"></div> 
 
    </div> 
 
</div>

+1

请包括您的实际代码...如果您不知道从哪里开始搜索关于伪元素':before - :after'和在颜色上使用不透明度'rgba()' – DaniP

+0

@DaniP I尝试过pesudo-elements,并且rgba()不会达到与Illustrator中的“繁殖”叠加相同的视觉效果。 – DimSum

+2

那么包括'代码'和所有关于你的问题的尝试,我们不能假设你已经完成了所有的事情 – DaniP

回答

2

这是我能为做的最好仅CSS解决方案。浏览器支持是一盏小灯,因为它使用:

div { 
 
    display: inline-block; 
 
    position: relative; 
 
} 
 
p { 
 
    position: absolute; 
 
    width: 75%; 
 
    top: 50%; 
 
    left: 75%; 
 
    transform: translateY(-50%); 
 
} 
 
span { 
 
    display: inline; 
 
    padding: 0.25rem 0.5rem; 
 
    color: white; 
 
    font-family: Arial, sans-serif; 
 
    font-weight: bold; 
 
    line-height: 2rem; 
 
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg=='); 
 
    -webkit-background-blend-mode: multiply; 
 
    background-blend-mode: multiply; 
 
    -webkit-box-decoration-break: clone; 
 
    -o-box-decoration-break: clone; 
 
    box-decoration-break: clone; 
 
}
<div> 
 
    <img src="http://lorempixel.com/300/250/people/6"> 
 
    <p><span>Lorem ipsum dolor. Lorem ipsum dolor.</span></p> 
 
</div>

由于@lharby指出,与不使用脱身background-blend-mode你可以尝试创建一个小的1px x 1 px PNG,近似于您要查找的内容。

除此之外,它看起来像JS将被要求。你看过lettering.js?我自己并没有使用它,尽管它可能比你想要的要多一点。

+0

非常感谢@hungerstar的努力!我快速浏览了['lettering.js'](http://letteringjs.com/),但是据我所知,换行功能需要一个'
'来确定哪里可以打破这条线。我想我必须推回给客户,他们可以拥有设计或全面的浏览器支持。 – DimSum

+0

对。我相信你可以用JS来解决问题,我只是不确定需要多少努力才能让JS处理所有的需求。 – hungerstar

0

文本实际上是事件的标题,所以它可以是任意长度。当它碰到容器/视口的边界时,它应该切换到第二,第三行。

也许尝试,只是包含文本的两倍 - 这样就可以放置一前一后,像这样:https://jsfiddle.net/xfn0dusw/ - 请注意,在后台(意思是,在Z轴)的克隆具有红色背景颜色和它的文字颜色设置为透明,前景中的没有背景,只有白色文字。由于格式相同(字体属性和填充),它们当然会占用完全相同的空间并在相同的点处断开。克隆文本周围的额外div是必要的,所以我们可以绝对定位这个 - 定位跨度将取代它的“内联”属性。

.container { 
 
    position: relative; 
 
    padding: 2em; 
 
    line-height: 2; 
 
    border: 1px solid #000; 
 
    background: #eee; 
 
} 
 

 
p { 
 
    margin: 0; 
 
} 
 

 
.clone { 
 
    position: absolute; 
 
    top: 2em; 
 
    left: 2em; 
 
    right: 2em; 
 
} 
 

 
span { 
 
    position: relative; 
 
    z-index: 1; 
 
    padding: .25em 1em; 
 
    -webkit-box-decoration-break: clone; 
 
    box-decoration-break: clone; 
 
    color: #fff; 
 
} 
 

 
.clone span { 
 
    z-index: 0; 
 
    color: transparent; 
 
    background: red; 
 
}
<div class="container"> 
 
    <p><span>Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor.</span></p> 
 
    <div class="clone"><span>Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor. Lorem ipsum dolor.</span></div> 
 
</div>

我离开了这里所有的其他的东西(图像,混合模式) - 但这个想法应该是清楚的:应用背景色和混合模式的克隆,并赢得了”不会影响文本,因为这是在其他元素。


如果有两次在那里的文字应该提高关于SEO和/或可访问任何问题,那么也许不包括在HTML直接克隆的文本,但克隆与JS插入,然后/或添加aria-hidden以将其从使用屏幕阅读器等辅助技术的用户中隐藏起来。 (将文本放入自定义数据属性中,然后将其用作伪元素/生成内容的值可能是获取“克隆”的另一种方式。)

纯化者可能会皱起了眉头,在文件中两次;但考虑替代品 - 就像图形部门说的那样,“好吧,让我们把整个织物当做一个图像吧!”,或应用复杂的JS逻辑人为地将文本分解为多个部分 - 我喜欢这种方法的相对简单性:让我们让浏览器做,它最擅长的 - 根据可用空间动态地呈现文本和应用换行符。

+0

真的很酷的主意!从来没有这样想过。感谢您的时间! – DimSum

相关问题