I'm very new to HTML/CSS and I'm trying to display some text as like 50% transparent. So far I have the HTML to display the text with full opacity
<html><font color=\"black\" face=\"arial\" size=\"4\">THIS IS MY TEXT</font></html>
However, I'm not sure how to change its opacity. I've tried looking online, but I'm not sure exactly what to do with the code I find.
There is no CSS property like background-opacity that you can use only for changing the opacity or transparency of an element's background without affecting the child elements, on the other hand if you will try to use the CSS opacity property it will not only changes the opacity of background but changes the opacity of all the child elements as well. In such situation you can use RGBA color introduced in CSS3 that includes alpha transparency as part of the color value. Using RGBA color you can set the color of the background as well as its transparency.
Your best solution is to look at the "opacity" tag of an element.
For example:
.image
{
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
So in your case it should look something like :
<html><span style="opacity: 0.5;"><font color=\"black\" face=\"arial\" size=\"4\">THIS IS MY TEXT</font></html>
However don't forget the tag isn't supported in HTML5.
You should use a CSS too :)
Just use the rgba
tag as your text color. You could use opacity
, but that would affect the whole element, not just the text. Say you have a border, it would make that transparent as well.
.text
{
font-family: Garamond, serif;
font-size: 12px;
color: rgba(0, 0, 0, 0.5);
}
What about the css opacity
attribute? 0
to 1
values.
But then you probably need to use a more explicit dom element than "font". For instance:
<html><body><span style=\"opacity: 0.5;\"><font color=\"black\" face=\"arial\" size=\"4\">THIS IS MY TEXT</font></span></body></html>
As an additional information I would of course suggest you use CSS declarations outside of your html elements, but as well try to use the font css style instead of the font html tag.
For cross browser css3 styles generator, have a look at http://css3please.com/
Easy! after your:
<font color=\"black\" face=\"arial\" size=\"4\">
add this one:
<font style="opacity:.6">
you just have to change the ".6" for a decimal number between 1 and 0
Check Opacity, You can set this css property to the div, the <p>
or using <span>
you want to make transparent
And by the way, the font tag is deprecated, use css to style the text
div {
opacity: 0.5;
}
Edit: This code will make the whole element transparent, if you want to make ** just the text ** transparent check @Mattias Buelens answer
If you use opacity
to a element, entire element effect that(background+other things in it),you can use mix-blend-mode
to the CSS attributes of the specific element,
Refer these sites:
Source: Stackoverflow.com