3

I followed a tutorial online to make this neat little tabbed div content display but I seem to be having an issue when setting the opacity on the background. By doing this it reveals the hidden content. I've tried playing around and setting opacity at differnt layers but I havent had any luck. Here's an example that you can see. Let me know what you guys think

HTML

    <div class="tabs">
        <div class="tab">
            <input type="radio" id="tab-1" name="tab-group-1" checked>
            <label for="tab-1">Tab1</label>

       <div class="content" id="scrollbar">
            <div id="tabcontenttitle"><h1 class="h1titles">title 1</div>
            <div id="scrollbar" style="overflow: auto; height: 185px;  width: 100%; padding-right: 19px;">  <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. <br /><br />Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />

             <p>Nulla facilisi. In nec suscipit quam. In hac habitasse platea dictumst. Phasellus placerat eu augue nec iaculis. Praesent sapien massa, varius nec dolor ac, pulvinar faucibus ipsum. In hac habitasse platea dictumst. Curabitur rhoncus varius leo vel pharetra.</p><br />
<p>Vivamus eget bibendum nulla, vel suscipit arcu. In iaculis, lorem sit amet porta bibendum, mauris purus auctor lorem, in accumsan ipsum massa vel purus. Donec neque justo, posuere sed velit condimentum, tempor elementum arcu. Phasellus rhoncus porta odio et tincidunt. Aliquam facilisis non nisl id molestie. Cras commodo sem ut elementum ultricies. Aliquam gravida, arcu eget vestibulum gravida, leo metus tempor quam, eleifend mollis sapien dui sed justo. </p><br />

<p>Nunc eget odio ac magna facilisis bibendum. Proin eu posuere justo, eu adipiscing arcu. Vivamus et urna accumsan, ultrices diam sed, eleifend odio. Donec consequat lorem nec ipsum scelerisque fermentum.</p></div>

                    </div> 
   </div>

        <div class="tab">
            <input type="radio" id="tab-2" name="tab-group-1">
            <label for="tab-2">Tab2</label>

       <div class="content">
            <div id="tabcontenttitle"><h1 class="h1titles">title 2</div>
                    <div id="scrollbar" style="overflow: auto; height: 185px;  width: 100%; padding-right: 19px;">             <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br /><br />Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />
 <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br /><br />Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />
                    </div>
             </div> 
        </div>

CSS

#scrollbar::-webkit-scrollbar-track
{
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
    background-color: #000;
}

#scrollbar::-webkit-scrollbar
{
    width: 12px;
    background-color: #F5F5F5;
}

#scrollbar::-webkit-scrollbar-thumb
{
    background-color: #cd2429;  
}


.tabs {
  position: relative;   
  min-height: 200px; /* This part sucks */
  clear: both;
margin-left: 0px;
margin-top: 10px;
}
.tab {
  float: left;
}
.tab label { 
top: -1px;
font-family: font1;
font-size: 20px;
  background: #000; 
  color: #fff;
  padding: 7px; 
  margin-left: -1px;    
  position: relative;
  left: 1px; 
}
.tab [type=radio] {
  display: none;   
}
.content {
  position: absolute;
  top: 28px;
  left: 0;
  right: 0;
  bottom: 0;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 20px;
  width: 460px; height: 230px;-webkit-border-radius: 5px;
-webkit-border-top-left-radius: 0;
-moz-border-radius: 5px;
-moz-border-radius-topleft: 0;
border-radius: 5px;
border-top-left-radius: 0;color: #fff; background-color: rgba(0,0,0,.6);

  line-height: 20px;  overflow: hidden; font-family: Tahoma, Geneva, sans-serif; font-size: 12px;
}
[type=radio]:checked ~ label {
    background: #cd2429;
  z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
  z-index: 1;
}

#tabcontenttitle {style="display: block; clear: both; position: relative; padding-bottom: 10px;}
.tabcontenttext {style="overflow: auto; height: 15px;  width: 100%; padding-right: 19px;}
RomeNYRR
  • 877
  • 4
  • 19
  • 34
  • 1
    The problem with opacity is that it is, well.. Opaque. Setting the opacity at different levels won't do you much good, since everything within the outmost opaque element will also be opaque. I would suggest taking a look at [this post](http://stackoverflow.com/questions/2356711/create-non-transparent-div-on-top-of-transparent-parent-element). – EscalatedQuickly Dec 22 '13 at 09:42

2 Answers2

1

In CSS section .content replace background-color: rgba(0,0,0,.6); with background-color: #282828;

The background transparency set to 0.6 reveals the content lying under the displayed layer.


New answer

In section .content replace color: #fff; with color: transparent;.

In section [type=radio]:checked ~ label ~ .content add color: #fff;; after the same section add the following code:

.content * {
visibility: hidden;
}

[type=radio]:checked ~ label ~ .content * {
visibility: visible;
}

This code makes the text color of the underlying layer transparent ( = invisible! ) and hides all the elements inside it.

Andrea Riva
  • 166
  • 4
  • Unfortunately if I did that, then I would lose the opacity that I'm looking for =/. I have a background splash image that I want this div to be opaque on top of – RomeNYRR Dec 22 '13 at 19:57
  • EDIT: I've just had a new idea. Let me know if it solves your problem! :) – Andrea Riva Dec 24 '13 at 19:50
1

you can use from background-color: rgba(0,0,0,.5);

Abbas Rahimi
  • 202
  • 1
  • 5
  • 15