CSS RGBA边框/背景alpha双 [英] CSS RGBA border / background alpha double

查看:155
本文介绍了CSS RGBA边框/背景alpha双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个有很多透明度的网站上工作,我想我会尝试完全在RGBA构建它,然后做回退的IE。我需要一个facebox样式的边框效果,其中外部边框是圆形的,并且比它包围的框的背景不透明。

I'm working on a website that has a lot of transparency involved, and I thought I would try to build it entirely in RGBA and then do fallbacks for IE. I need a "facebox" style border effect, where the outer border is rounded and is less opaque than the background of the box it surrounds.

最后一个例子从 http://24ways.org/2009/working-with-rgba-colour 似乎建议这是可能的,但我似乎无法得到它的工作。当我尝试以下:

The last example from http://24ways.org/2009/working-with-rgba-colour seems to suggest that it's possible, but I can't seem to get it to work. When I try the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

 <title>RGBA Test</title>
 <style type='text/css'>
   body {
     background: #000;
     color: #fff;
   }
   #container {
     width: 700px;
     margin: 0 auto;
     background: rgba(255, 255, 255, 0.2);
     border: 10px solid rgba(255, 255, 255, 0.1);
     padding: 20px;
   }
  </style>
</head>
<body>
  <div id='container'>
    This should look like a facebox.
  </div>
</body></html>

看起来像是元素边框下方的背景extends,这会导致像素值得到加在一起。因此,当背景和边界都是半透明的时,边界总是比元素的背景更不透明。这正好与我想实现的相反,但它似乎应该是可能的基于我看到的例子。

It seems like the background "extends" underneath the border of the element, which causes the pixel values to get added together. Thus, when both the background and the border are semi-transparent, the border will ALWAYS be more opaque than the background of the element. This is exactly the opposite of what I am trying to achieve, but it seems like it should be possible based on the examples I've seen.

我还应该添加我不能使用容器内的另一个元素,因为我也要在容器上使用border-radius来获取圆角,而webkit如果分配了一个背景,就会对子元素的角落进行平方,

I should also add that I can't use another element inside the container, because I'm also going to use a border-radius on the container to get rounded corners, and webkit squares the corners of the child elements if they have a background assigned, which would essentially mean a rounded outer border with square contents.

对不起,我不能发布此图片...显然我没有足够的代表来发布图片。

Sorry I can't post an image of this... Apparently I don't have enough rep to post an image.

推荐答案

您可以使用新的 background-clip:padding-box; 属性来得到这个。它计算背景从框中开始的位置。
有关更多详细信息和示例,请查看此处

You can use the new background-clip: padding-box; property to get this going. It calculates where from should the background start within a box. For more details and examples, check here

这篇关于CSS RGBA边框/背景alpha双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆