影响子div的CSS不透明度

时间:2014-01-14 20:18:29

标签: html css

我在this的帮助下尝试了opacity。除了一件事,它确实运作良好。我想要使​​用不透明度的div也包含其他内容。所以,当我在父div中使用opacity时,子div也会受到影响!该怎么做只影响父div而不影响子div?任何帮助将不胜感激。谢谢。

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 个答案:

答案 0 :(得分:1)

不要使用不透明度,它会影响所有子元素

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

仅模糊父元素。