Solved

css alpha opacity on multiple div, cancel alpha effect on image

Posted on 2004-08-05
18
1,802 Views
Last Modified: 2008-01-09
Hi,

for a web page developing the design is so that a background image is visable through a colored <div> section with alpha effect, defined like this:
<div style="filter: alpha(opacity=80, style=0); background-color: rgb(255,255,255); width:563;height:92%; border: 1px solid rgb(128,128,128)">
 here come content
</div>

The content is another <div> section wich contains text or image, which should not be transparent but is since the parent div has the alpha effect. So, how to make the image so that  background image would not be visible under the image but is visble through the colored div section.

Thanks in advance.
0
Comment
Question by:dzelde
  • 7
  • 6
  • 4
18 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11731628
Hi

Do you mean so the background image would not be visible over the text but over the div? The easiest way to do that is to set another <div> around the content that has a style with no filter, but that just kind of ruins the purpose of opacity anyways. I'm not quite sure exactly what you want.

If you want the alpha filter to be for Mozilla and Safari also, add this to your styles:
moz-opacity:0.8; opacity:0.8
Unfortunately, all the child elements of the <div> will  then inherit the opacity, but that can easily be remedied by setting the child elements to have opacity of 1.0 or 100%

Regards,
Zyloch
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 100 total points
ID: 11731648
It has to be outside of the div with the filter.  Then put it iin front of the filtered div with absolute positioning and a z-index:

<div style="position:absolute; left:100px; top:100px; z-index:10">
content here
</div>

You will have to determine the value of the top and left properties to get it postioned where yu want it.

This is a bad way to do design and is going to cause you problems trying to maintain the page, but gee whiz effects are usually bad design anyway, so I guess it does not matter.

Cd&
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11731666
You can, of course, try putting another <div> around your content that has style of
filter: alpha(opacity=100, style=0);
but that's just to try
0
 
LVL 1

Author Comment

by:dzelde
ID: 11731678
thats what i thought, that making child elements to have opacity of 1.0 or 100 will make it not transparent but it is.

here is an example:
****
<html>
<head></head>
<body background="img/s_elephant.jpg">
<div style="filter: alpha(opacity=80, style=0); background-color: rgb(255,255,255); width:563;height:92%; border: 1px solid rgb(128,128,128)">
    <p style="color: rgb(204,204,204);">
        <div style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px;">
            <img src="img/zebres.jpg" />
        </div>
    </p>
</div>
</body>
****
you can see that the image zebres.jpg is also transparen, making it possible to see the "s_elephant.jpg" though the "zebres.jpg" and makes it too fancy.

Martins.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11731689
Like Cd, said, it'll be complicated then. I would recommend removing the alpha opacity altogether. Is there any specific reason for needing it?

Regards
0
 
LVL 1

Author Comment

by:dzelde
ID: 11731735
Its just that a designer supplied me this design to implement.. isnt there another way than using abolute positioning.. :( ?

Martins.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11731776
Before you try something new, try to take one last stab at it. The child <div> should be like this:
<div style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px; background-color:white;">

Regards
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11731795
>>>isnt there another way than using abolute positioning.

Yes tell the designer their design is defective, and if they think it is implementable then they should demostrate how or admit they are a moron. ;^)

Cd&
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 36

Expert Comment

by:Zyloch
ID: 11731810
Ouch, playing hardball there Cd :)
WARNING: Do above statement at your own expense of turning into a homeless hobo because you lost a job.
0
 
LVL 1

Author Comment

by:dzelde
ID: 11731840
>>>> Yes tell the designer their design is defective, and if they think it is implementable then they should demostrate how or admit they are a moron. ;^)
lol ;)) there is some truth in that!

making the background white for the child div doesnt seem to work either.. i tried to work around with iframe but no luck.. :/
i guess i willl rather exchange some phrases with designer.. hmm.

M.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11731845
You might as well. Make sure to tell them that their website will be less cross-browser compatible if they have the filters, which is true :)
0
 
LVL 1

Author Comment

by:dzelde
ID: 11731902
Yea... true about compatiblity.
 so no other way to jump out of div than absolute positioning, which i wont be using in my case.. i guess i might leave the question open for a day or two, since  usually it is possible to define any new style for a child section like div,span or any other..

Thanks a lot, anyway.

M.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11731974
>>>since  usually it is possible to define any new style for a child section like div,span or any other.

Except the non-standard filters are not implemented as true style properties.  They are more closely related to behaviours.

Digging through old documentation I see a possibility.  If the child element is given form with a specified width, and height it might hold an opacity value of its own; at least for IE, not sure that will help for MOZ, but moz opacity is unreliable anyway.

Cd&
0
 
LVL 1

Author Comment

by:dzelde
ID: 11733311
Setting width and height, and theit own opacity for the inner child elements like this:
...
        <div  width="190" height="289" style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px; background-color:white;">
            <img src="img/zebres.jpg" width="190" height="289" style="filter: alpha(opacity=100, style=0);"/>
        </div>
...
Does not solve the problem. did i understood the possibility correctly?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11743173
No, I think the child has to be a block element. More like:

<div  width="190" height="289" style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px; background-color:white;">
<div style="width:190px;height:289px;filter:alpha(opacity=100,style=0)">
            <img src="img/zebres.jpg" width="190" height="289" />
</div>
        </div>

Cd&
0
 
LVL 1

Author Comment

by:dzelde
ID: 11744227
i inserted your code as another div but its not workin:
***
<html>
<head></head>
<body background="img/s_elephant.jpg">
<div width="190" height="289" style="filter: alpha(opacity=80, style=0); background-color: rgb(255,255,255); width:563;height:92%; border: 1px solid rgb(128,128,128)">
    <p style="color: rgb(204,204,204);">
        <div  width="190" height="289" style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px; background-color:white;">
            <img src="img/zebres.jpg" width="190" height="289" style="filter: alpha(opacity=100, style=0);">
        </div>
    </p>
    <div  width="190" height="289" style="filter: alpha(opacity=100, style=0); margin-left: 10px; margin-right: 10px; margin-top: 10px; font-family: Verdana; font-size: 10px; background-color:white;">
<div style="width:190px;height:289px;filter:alpha(opacity=100,style=0)">
            <img src="img/zebres.jpg" width="190" height="289" />
</div>
        </div>
</div>
</body>
***
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11744319
As it seems to still not be working, I think iframes would be the best solution. You could messily realign the inner <div> using absolute or relative positioning, but it would be just that, messy. If you really want the content background to be not transparent, use an iframe.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now