Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1856
  • Last Modified:

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

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
dzelde
Asked:
dzelde
  • 7
  • 6
  • 4
1 Solution
 
ZylochCommented:
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
 
COBOLdinosaurCommented:
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
 
ZylochCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dzeldeAuthor Commented:
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
 
ZylochCommented:
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
 
dzeldeAuthor Commented:
Its just that a designer supplied me this design to implement.. isnt there another way than using abolute positioning.. :( ?

Martins.
0
 
ZylochCommented:
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
 
COBOLdinosaurCommented:
>>>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
 
ZylochCommented:
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
 
dzeldeAuthor Commented:
>>>> 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
 
ZylochCommented:
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
 
dzeldeAuthor Commented:
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
 
COBOLdinosaurCommented:
>>>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
 
dzeldeAuthor Commented:
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
 
COBOLdinosaurCommented:
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
 
dzeldeAuthor Commented:
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
 
ZylochCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now