问题
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.
回答1:
opacity
applies to the whole element, so if you have a background, border or other effects on that element, those will also become transparent. If you only want the text to be transparent, use rgba
.
#foo {
color: #000; /* Fallback for older browsers */
color: rgba(0, 0, 0, 0.5);
font-size: 16pt;
font-family: Arial, sans-serif;
}
Also, steer far, far away from <font>
. We have CSS for that now.
回答2:
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
回答3:
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);
}
回答4:
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 :)
回答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/
回答6:
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
回答7:
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.
回答8:
try to play around with mix-blend-mode: multiply;
color: white;
background: black;
mix-blend-mode: multiply;
MDN
tutorial
来源:https://stackoverflow.com/questions/10835500/how-to-change-text-transparency-in-html-css