简体   繁体   English

是否可以使div背景具有不透明性,但某些像素边界具有渐变?

[英]Is it possible to have div background with opacity but with gradient some pixel borders?

I have a div with 0.5 transparency. 我有一个透明度为0.5的div。 This acts as a darkening rectangle over a bigger background slider image (an outer div) to make the text more readable over the slider background picture. 这在较大的背景滑块图像(外部div)上用作变暗的矩形,以使文本在滑块背景图片上更具可读性。

<div class="darken-rectangle">
   <!-- inner text container divs go here -->
</div>

CSS: CSS:

.darken-rectangle {
   padding: 30px 30px 30px 30px;
   background-color: rgba(0, 0, 0, 0.5);
}

This works great, however I would like to a few pixel (3px-6px) gradient border for the rectangle which drives the alpha from the outer light to the inner darken. 这很好用,但是我想为矩形设置几个像素(3px-6px)的渐变边框,该边框将alpha从外部光线驱动到内部暗处。

Unfortunately I can not find how to do this, even does not know is it possible with pure CSS, or do I have to create 4 png images for the 4 "border and arrange the layout? 不幸的是,我找不到方法,甚至不知道纯CSS是否可行,还是我必须为4“边框创建4 png图像并安排布局?

I think what you want is box-shadow , see jsFiddle 我认为您想要的是box-shadow ,请参阅jsFiddle

HTML 的HTML

<div class="darken-rectangle">
    Test Text
</div>

CSS 的CSS

.darken-rectangle {
    /* ... */
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 1);
}
.darken-rectangle {
   padding: 30px 30px 30px 30px;
   background-color: rgba(0, 0, 0, 0.5);
   box-shadow: 0px 0px 5px rgba(0, 0, 0, 1);
   border-radius: 3px;
}

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

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