简体   繁体   English

图片上的CSS黑色渐变

[英]CSS black gradient over image

Please take a look at this screenshot. 请看这张截图。 It's the head part of the posts in my blog. 这是我博客中帖子的头部。 See that the header image is covered by a black gradient. 看到标题图像被黑色渐变覆盖。 I created that using Photoshop because I don't know how to do it on CSS. 我使用Photoshop来创建它,是因为我不知道如何在CSS上做到这一点。

It's based on a wordpress theme. 它基于wordpress主题。

在此处输入图片说明

Here's the code: 这是代码:

HTML/PHP HTML / PHP

 <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <div class="post-title-container" style="background: url('<?php echo $image[0]; ?>') no-repeat center center;"> <?php if ( is_single() ) : the_title( '<h1 class="post-title-text">', '</h1>' ); else : the_title( sprintf( '<h2 class="post-title-text"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); endif; ?> </div> <?php endif; ?> 

CSS CSS

 .post-title-container { position: relative; width: 100%; height: 300px; opacity: 1; box-shadow: none; background-size: 100% auto; } .post-title-text { color: #FFF !important; margin-bottom: 0; padding: 18% 10% 0% 10%; width: 80%; z-index: 1; line-height: 1.2; position: absolute; font-size: 4.14286rem; } .post-title-text > a { color: #FFF !important; } .post-title-text > a:hover { color: rgba(255, 255, 255, 0.8) !important; } 

Any ideas? 有任何想法吗? Thanks. 谢谢。

Unfortunately, there is no cross-browser support for doing a gradient mask yet. 不幸的是,尚无跨浏览器支持进行渐变蒙版。 Here is a question that answers this: Using CSS, can you apply a gradient mask to fade to the background over text? 这是一个可以回答此问题的问题: 使用CSS,您可以应用渐变蒙版来淡化文本上方的背景吗?

I would suggest creating a transparent PNG with a gradient of opacity from 100% to 0% that is the same size as the image and overlaying it. 我建议创建一个透明度从100%到0%且与图像大小相同的透明PNG并将其覆盖。 Otherwise, just stick to what you've got. 否则,请坚持您所拥有的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM