2014-01-14 138 views
-1

我在this的幫助下試了opacity。除了一件事外,它確實運作良好。我想要使​​用不透明度的div也有其他內容。所以,當我在那個父div中使用opacity時,子div也會受到影響!怎麼做才能實現只有父div而不是子div?任何幫助將不勝感激。謝謝。影響子div的CSS不透明度

enter image description here

HTML:

<div id="profile_rightbar"> 

      <div id="shortcuts"> 
       <div class="icon pink"> 
        <a href="#"> 
         <p>Pictures</p> 
         <p>210</p> 
        </a> 
       </div> 
       <div class="icon green"> 
        <a href="#"> 
         <p>Videos</p> 
         <p>210</p> 
        </a> 
       </div> 
       <div class="icon blue"> 
        <a href="#"> 
         <p>Forums</p> 
         <p>210</p> 
        </a> 
       </div> 
       <div class="icon orange"> 
        <a href="#"> 
         <p>Pages</p> 
         <p>210</p> 
        </a> 
       </div> 
       <div class="icon pink"> 
        <a href="#"> 
         <p>Followers</p> 
         <p>210</p> 
        </a> 
       </div> 
       <div class="icon green"> 
        <a href="#"> 
         <p>Following</p> 
         <p>210</p> 
        </a> 
       </div> 
      </div> 

      <div id="status"> 
       <p>Always do your best. What you plant now, you will harvest later.</p> 
      </div> 

      <div id="write"> 
       <textarea id="redactor" name="content"> 
     <h2>Hello and Welcome</h2> 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 
       </textarea> 
      </div> 

      <div id="activity"> 

       <div class="picture"> 
        <a href="#"> 
         <p>The world is so perfect. How can one not love this beautiful world.</p> 
         <img src="image/world.jpg"> 
        </a> 
       </div> 

       <div class="picture"> 
        <a href="#"> 
         <p>The world is so perfect. How can one not love this beautiful world.</p> 
         <img src="image/world.jpg"> 
        </a> 
       </div> 

       <div class="forum"> 
        <a href="#"> 
        </a> 
       </div> 

       <div class="video"> 
        <a href="#"> 
        </a> 
       </div> 

       <div class="page"> 
        <a href="#"> 
        </a> 
       </div> 

       <div class="following"> 
        <a href="#"> 
        </a> 
       </div> 

      </div> 


     </div> 
     <div class="clear_right"></div> 

CSS:

html, body { 
    width: 100%; 
    height: 100%; 
} 

#main_wrapper { 
    width:100%; 
    height: 100%; 
    background:url(../image/pantera.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover; 
     -moz-background-size: cover; 
     -ms-background-size: cover; 
     -o-background-size: cover; 
      background-size: cover; 
} 

#profile_page { 
    width: 800px; 
    margin: 0 auto; 
    overflow: hidden; 
    border: 1px solid red; 
} 

#username h1 { 
    text-align: center; 
    color: white; 
} 

#profile_leftbar { 
    width: 210px; 
    float: left; 
} 

#profile_picture { 
    background-color: white; 
    border-radius: 10px; 
    border: 1px solid #dbdbdb; 
} 

#profile_picture img { 
    display: block; 
    margin: 0 auto; 
    border: none; 
    max-width:190px; 
    padding: 8px; 
} 

#about { 
    background: #f4f4f4; 
    border-radius: 5px; 
    margin-top: 8px; 
    border: 1px solid #dbdbdb; 
} 

#about p { 
    text-align: center; 
    color: #000000; 
    padding-top: 3px; 
    padding-bottom: 3px; 
} 

#about hr { 
    height:1px; 
    border:0px solid ; 
    border-top:1px solid #ccc; 
} 

#follow_message { 
    width: 210px; 
    margin: 5px auto; 
} 

#follow_message li { 
    list-style-type: none; 
    float: left; 
    margin-left: 3px; 

} 

#follow_message a { 
    display: block; 
    width: 101px; 
    text-align: center; 
    height: 30px; 
    color: white; 
    text-decoration: none; 
    line-height: 30px; 
    margin: 2px 0; 
    background: maroon; 
} 





#profile_rightbar { 
    float: right; 
    width: 590px; 
} 

#shortcuts { 
    overflow: hidden; 
    width: 588px; 
    margin: 0 auto; 
} 

#shortcuts div { 
    float: left; 
    margin: 4px; 
} 

.icon a { 
    text-decoration: none; 
    text-align: center; 
    display: block; 
    color: white; 
    border-radius: 5px; 
    width: 88px; 
    padding: 1px; 
} 

.icon a:hover { 
    text-decoration: underline; 
} 

.pink a { 
    background-color:#d63175; 
} 

.green a { 
    background-color:#51b73c; 
} 

.blue a { 
    background-color:#2f8ae0; 
} 

.orange a { 
    background-color:#f7a809; 
} 

#status { 
    background-color:white; 
    box-shadow:5px 5px 20px 1px black; 
    max-width:490px; 
    word-wrap:break-word; 
    padding:6px; 
    margin: 15px auto; 
    text-align:center; 
    font-size:30px; 
    line-height: 32px; 
} 

#write { 
    width: 575px; 
    margin: 0 auto; 
} 

#write textarea { 
    font-size:20px; 
    max-width:575px; 
    width: 575px; 
} 

#activity { 
    margin: 10px; 
    width: 575px; 
} 

#activity { 
    border: solid red; 
    opacity: 0.2; 
    filter: alpha(opacity=20);  /* IE8 and lower */ 
    zoom: 1; 

#activity div { 
    background: white; 
    margin: 0 auto; 
} 

#activity .picture a img { 
    display: block; 
    max-width: 540px; 
    margin: 0 auto; 
} 

.picture a { 
    color: black; 
    text-decoration: none; 
} 

.picture a p { 
    margin-top:15px; 
    margin-left:15px; 
} 
+1

「不透明度」將始終影響子/後代元素。如果你想堅持使用'opacity',你可以爲你的「父div」創建一個兄弟元素,並將父div的樣式移動到該兄弟元素,然後定位這個兄弟元素,這樣它也是父div的位置,所以它*顯示爲*父div(父div將顯示爲不可見,因此您可以看到兄弟div)。然後,您可以在該兄弟元素上設置不透明度,這隻會影響它,而不會影響原始父div的後代元素。 – ajp15243

+0

@ ajp15243感謝您的幫助。你能否詳細說明一下,或者如果可能的話在這裏回答。再次感謝。 – Robin

+0

@AlienArrays我很抱歉,我認爲這會有所幫助。 – Robin

回答

1

不使用不透明它會影響所有的子元素

使用 background-color : rgba(255,255,255,0.2);

它只模糊父元素。

+0

一個簡單的方法,使這種不支持'rgba'的舊瀏覽器兼容的是創建一個20%的不透明度白色PNG,並將其用作背景圖片(我認爲多數民衆贊成ie6 +) – x4rf41

+0

@ x4rf41我認爲你需要一個PNG修復IE6(和7?),但除此之外,一個透明的PNG肯定會給舊的瀏覽器兼容性。 – ajp15243

+0

即時100%肯定PNG在IE7上工作正常,雖然不確定6,但你可能是對的。但在這一點上,你不能做任何事情 – x4rf41