473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to make the text of sub elements not gain the parents Opacity setting?

Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. <div style="opacity: 0.5; background-color: #000;">
  2.     <span style="opacity: 1.0;">Testing</span>
  3. </div>
I know from this example, that sub-elements automatically inherit the parents styling, but is there anyway for me to be able to make the Text ( sub elements ) not gain the parents Opacity setting?

Or am I going to have to do absolute positioning with this? =\
Nov 10 '10 #1
3 1651
Death Slaught
1,137 1GB
Opacity is essentially a filter - It is placed over the element rather than being part of the element. Yes, the sub-element is inheriting the parents styling, but the opacity is being negated by the sub-elements styling. The browser will always use the style that is listed last.

It really doesn't matter what you set the opacity of your span to, if you absolutely position it, or just about anything really. The span is contained within a division with an opacity filter being placed over it, and its content. In other words, the span has an opacity of 1.0 and has an opacity of 0.5 being placed over it, making it the same color as the background.

Also, please remember that opacity is not supported in IE. You will have to use,
Expand|Select|Wrap|Line Numbers
  1. div {
  2.     -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";  /* IE8, must be listed first. */
  3.     filter: alpha(opacity=50);     /* IE5-7, must be listed second. */
  4. }


Regards, Death
Nov 10 '10 #2
Samishii23
246 100+
Yea I have the Opacity filters for IE, Mozilla, Webkit etc.
Sounds like i'll have to make 2 divs and place one over the other, or will that not work either?
Nov 10 '10 #3
Death Slaught
1,137 1GB
No, that wouldn't work either because your new division, and its content, would be contained by the parent division that has the opacity filter placed over it. Just to clarify, let's say that you put an opacity filter over the body element.

Expand|Select|Wrap|Line Numbers
  1. body {
  2.     opacity: 0.5;
  3. }

Now everything that you put inside of the body element is going to be affected by the opacity because the filter is being placed over it, and everything it contains.

One option would be; and I just realized that this may be what you meant before; would be to move the text outside of the division, and then absolutely position it to set on top of the division. The division of course would need a set width and height. Also, you could change the background color, the color of the text, or use a background image instead.


Regards, Death
Nov 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dean Edwards | last post by:
I am attempting to change the opacity of an image. I can modify opacity ok: function flip(pic, opacity){ pic.style.filter = 'alpha(opacity='+opacity+')'; } But I'm not familiar with...
0
by: kaeli | last post by:
All, The following is an example of what I'm trying to do: I have a box set to be partially transparent. I want the text in the box to NOT be partially transparent. This works in IE, but NN7 has...
3
by: Marek Mänd | last post by:
This posting will express my concern about the future of css3 forthcoming recommendation. I think for long time now, that the current implementation of CSS attribute opacity is less than usable...
5
by: AWesner | last post by:
I've been working on a project to help myself better understand how inherited classes work. I think I've learned more about classes by doing this than any other effort I've made. I've tried to...
1
by: mhoeneveld | last post by:
I am writing a small script to fade the opacity of an image/object. The script itself works fine only I do have some unwanted behaviour. I do use a tablecell object and the mouseover/mouseout to...
2
by: reidarT | last post by:
I want a windows form to act like the one in Outlook when you get a new message and it is visible for about a couple of seconds and then the opacity decreases and the form dissapears in the end I...
16
by: Darko | last post by:
Hi, I'm trying to get and set an element's opacity, but I'm stuck with, what a hell of surprise, Internet Explorer. As for getting the element's opacity, I have the following (not working) lines...
15
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it throws error. How I can change the opacity of an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.