473,400 Members | 2,145 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,400 software developers and data experts.

Dark font in spite of opacity

Hi!

I want to "paint" some blocks with text in it. As the box can overlap I
want the text to be transparent using opacity. Though, the text shall
stay well visible.

Here is what I produced so far:

<div style="overflow: hidden; white-space: nowrap; opacity: 0.7; width:
50px; background-color: Fuchsia;">
<div style="color: Black; opacity: 1;"Johanna from Orleans </div>
</div>

I want the text of Johanna be totally dark. How to achieve this?

Thanks

Rudi
Apr 23 '07 #1
5 6858
On 2007-04-23, Rudi Hausmann <ru*****@nospam.comwrote:
Hi!

I want to "paint" some blocks with text in it. As the box can overlap I
want the text to be transparent using opacity. Though, the text shall
stay well visible.
Do you mean you want the background to be transparent, but the text
opaque?
Here is what I produced so far:

<div style="overflow: hidden; white-space: nowrap; opacity: 0.7; width:
50px; background-color: Fuchsia;">
<div style="color: Black; opacity: 1;"Johanna from Orleans </div>
</div>

I want the text of Johanna be totally dark. How to achieve this?
As you've discovered, opacity sets a blending level for a box and its
descendents altogether to be blended onto whatever they're stacked on
top of.

To get the effect you want, you will need to change the document
structure so that the text is no longer a descendent of the fuchsia
element. You can do this with an absolutely positioned div.

<div style="position: relative">
<div style="background-color: magenta;
height: 50px; opacity: 0.7">
</div>
<div style="position: absolute; top: 0; bottom: 0; color: black">
Johanna from Orleans
</div>
</div>

The second div has background: transparent (the default, so I haven't
set it).

So we have a magenta box blended into its background with opacity 0.7.
It has no descendents. Sitting on top of it is another box with a
transparent background and opaque foreground.

You can set the second div to opacity: 0.9 or something of course if you
want to.

We put the whole lot in a containing div with position: relative to
establish a containing block in the right place for the absolutely
positioned one. That extra container should have no padding set on it.
It might not be necessary to have this div depending on your actual
example.

Note that opacity is CSS 3 but is reasonably well supported.
Apr 23 '07 #2
Ben C wrote:
On 2007-04-23, Rudi Hausmann <ru*****@nospam.comwrote:
>Hi!

I want to "paint" some blocks with text in it. As the box can overlap I
want the text to be transparent using opacity. Though, the text shall
stay well visible.

Do you mean you want the background to be transparent, but the text
opaque?
Exactly.
>Here is what I produced so far:

<div style="overflow: hidden; white-space: nowrap; opacity: 0.7; width:
50px; background-color: Fuchsia;">
<div style="color: Black; opacity: 1;"Johanna from Orleans </div>
</div>

I want the text of Johanna be totally dark. How to achieve this?

As you've discovered, opacity sets a blending level for a box and its
descendents altogether to be blended onto whatever they're stacked on
top of.

To get the effect you want, you will need to change the document
structure so that the text is no longer a descendent of the fuchsia
element. You can do this with an absolutely positioned div.

<div style="position: relative">
<div style="background-color: magenta;
height: 50px; opacity: 0.7">
</div>
<div style="position: absolute; top: 0; bottom: 0; color: black">
Johanna from Orleans
</div>
</div>

The second div has background: transparent (the default, so I haven't
set it).

So we have a magenta box blended into its background with opacity 0.7.
It has no descendents. Sitting on top of it is another box with a
transparent background and opaque foreground.

You can set the second div to opacity: 0.9 or something of course if you
want to.

We put the whole lot in a containing div with position: relative to
establish a containing block in the right place for the absolutely
positioned one. That extra container should have no padding set on it.
It might not be necessary to have this div depending on your actual
example.

Note that opacity is CSS 3 but is reasonably well supported.
Later on I want to drag and drop the elements. Therefor I do better not
divide the elements into two or three parts and live with the whole box
being blended.

The use case by the way: I have a lot of boxes representing dates/events
during a day. When the boxes overlap it should be visible. Transparency
would be nice. But maybe I make some overlaying divs in the overlapping
zone. Or I just display a warning text somewhere (a special background
or so) when overlapping occurs. This was the easies solution.
Apr 23 '07 #3
Scripsit Ben C:
Note that opacity is CSS 3 but is reasonably well supported.
I wouldn't call it reasonably well supported when IE, the most widely used
browser, has no support to the property. IE has its own code for setting
opacity, though: after
opacity: 0.7;
you would add
filter: alpha(opacity=70);
which deviates from the CSS 3 drafts but is the practical author's choice.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Apr 23 '07 #4
On 2007-04-23, Jukka K. Korpela <jk******@cs.tut.fiwrote:
Scripsit Ben C:
>Note that opacity is CSS 3 but is reasonably well supported.

I wouldn't call it reasonably well supported when IE, the most widely used
browser, has no support to the property. IE has its own code for setting
opacity, though: after
opacity: 0.7;
Good you pointed that out. I thought I heard somewhere IE did support
it.
you would add filter: alpha(opacity=70); which deviates from the CSS 3
drafts but is the practical author's choice.
Apr 23 '07 #5
Rudi Hausmann wrote:
>
Later on I want to drag and drop the elements. Therefor I do better not
divide the elements into two or three parts and live with the whole box
being blended.


How about something like this?

..bg {
position: relative;
top: 0em;
opacity: 0.5;
filter: alpha(opacity=70);
width: 4.5em;
background : yellow;
}
..text {
position: relative;
top : -1.3em;
width: 2.6em;
overflow: hidden;
white-space: nowrap;
padding : 0 .6em;
}
<div class="bg">&nbsp;</div>
<div class="text">Johanna from Orleans</div>

The color you're using was nasty so I changed it to yellow in this demo.
I also added some padding which increases the width. I also changed
everything to em.

If you want the text to lie flat within the colored background, change
top: 1.3em to 1em.

Apr 23 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

133
by: Philipp Lenssen | last post by:
Why is there no standardized and well-working way for a web-page to offer the font for download/embed it, in order to be displayed on the page? No matter what you think of the preferred font of a...
55
by: Haines Brown | last post by:
I've been setting font-size 1em; as the default in my style sheets. Until now, that seemed to be ok. But now I'm beginning to wonder. My aim is to have an easily readable, but not overly large...
2
by: chart43 | last post by:
Anyone working on a Mac and not setting any font-size at body level or even p level in their linked css but finding that while sites look good on one's own screen they look too big on Windows...
1
by: VR | last post by:
I designed an ASP.NET page and in the IDE design view the page looks just fine. It also looks fine when I view it in the browser on my development PC. When I look at the same page, using the...
60
by: deko | last post by:
As I understand it, most browser manufacturers have agreed on 16px for their default font size. So, this should be an accurate conversion for percentages: px % 16 = 100 14 = 87.5 13 =...
23
by: Schannah | last post by:
I'm trying to create a design which mimics the Radiohead website in the action on this page, but the problem is that they use PHP for the effect and I have no idea about PHP. I'm very amateur: fairly...
6
by: Rob | last post by:
I would like to show dark fonts (so that the text is readable and not greyed out) in a text box, however, I do Not want the text box to be Enabled, because I do not want the text box to ever have...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.