2013-01-20 71 views
0

我想添加一個不透明的襯底使用CSS。如何用CSS創建不透明底層?

你能幫我理解我做錯了什麼嗎?

CSS

popUp#translucent{ 
    width: 400px; 
    height: 100px; 
    background-color: black; 
    margin-left: auto; 
    margin-right: auto; 
    position:fixed; 
    opacity: .4; 
} 

popUp#content{ 
width:400px; 
height: 100px; 

} 
#popContainer{ 
width: 400px; 
height: 100px; 
display: visible; 
position: fixed; 
z-index: 1000; 
} 

HTML

<div id="popContainer"> 
    <popUp id="translucent"></popUp> 
    <popUp id = "content"> 
     <button class="btn large btn-custom" data-h="193" data-s="32" data-l="64" ,="" data-p="15">Alpha</button> 
    </popUp> 
</div> 

http://jsfiddle.net/CeRX3/

感謝

+2

從有效標記開始; 'popUp'不是一個HTML元素,看起來你只是做了它。另外:',=「」'...什麼? –

+0

@wesleyMurch我試圖按照http://iwearshorts.com/blog/annoying-css-opacity-inherited-by-children/ – user1530249

回答

0

改變背景顏色爲灰色,並在半透明的不透明度爲0.1。它看起來更加半透明。

1

以下是使用CSS爲按鈕創建底圖的方法。

通過使用w3學校的代碼製作的這個fiddle

HTML

<div class="background"> 
    <div class="transbox"> 
    <p>This is some text that is placed in the transparent box. 
    This is some text that is placed in the transparent box. 
    This is some text that is placed in the transparent box. 
    This is some text that is placed in the transparent box. 
    This is some text that is placed in the transparent box. 
    </p> 
    </div> 
    </div> 

CSS

div.background 
    { 
    width:500px; 
    height:250px; 
    background:url(http://www.w3schools.com/css/klematis.jpg) repeat; 
    border:2px solid black; 
    } 
div.transbox 
    { 
    width:400px; 
    height:180px; 
    margin:30px 50px; 
    background-color:#ffffff; 
    border:1px solid black; 
    opacity:0.6; 
    } 
div.transbox p 
    { 
    margin:30px 40px; 
    font-weight:bold; 
    color:#000000; 
    } 

您可以使用上面的代碼。在CSS中有不透明的問題。

CSS不透明的問題 當我們將子元素添加到此代碼 影響的html元素時,就會出現問題。所有子元素將繼承相同的不透明度設置,即使您嘗試 爲所有這些元素指定了完全不透明度(這對於執行 來說太麻煩)。

The Hacky Solution 我們該如何解決這個問題?在某些情況下,您可以使用絕對定位在視覺上模擬元素之間的親子關係,並且此 將解決該問題。 然後,如果你想解決你的問題,那麼你可能不得不使用一種解決方法的目的。

+0

上的指南我不想爲按鈕創建底層,而是使用黑色按鈕後面的不透明框。那有意義嗎?這可能與CSS完成? – user1530249

+0

plz現在檢查,如果它符合你的要求 – Neji

+0

謝謝,但我想我不解釋我想完成什麼。考慮一下http://iwearshorts.com/opacity/例子,注意文本是如何不透明的,但它背後的容器是?我試圖用我的上面的代碼來實現這個效果。我希望盒子中的按鈕和所有其他內容不是半透明的,但黑盒本身是半透明的。這可能嗎? – user1530249