-2

I have this code

<h2 style="background-color: #c0c0c0; padding: 1em; max-width: 15em; opacity: 0.2; ;margin: 1em 10px; text-align: right;"><strong>HANDMADE TIES
</strong>DISCOVER NOW</h2>
&nbsp;

But I cannot figure out how to make the background opacity only, while text remains of its own color. Also I would like the text Handmade ties to be H2 while Discover now to be a paragraph.

Dale K
  • 25,246
  • 15
  • 42
  • 71

3 Answers3

1

Opacity will the effect all styles of the element. Try to Use

background: rgba(192,192,192, 0.2);

Hope it helps.

Anji
  • 689
  • 1
  • 5
  • 24
  • hello Anji, thanks a lot. I have tried with this code but the background is totally transparent and not sure why it changed the position of the text from right to left. Not sure why. :( – Boundless Dec 25 '18 at 18:51
1

<h2 style="background-color: rgba(192, 192, 192, 0.5); padding: 1em; max-width: 15em;  ;margin: 1em 10px; text-align: left;"><strong>HANDMADE TIES
</strong>DISCOVER NOW</h2>
&nbsp;
0

Seems like you are trying to make a background colour transparent and want the font content to remain untouched from background. The possible solution is you can add a transparent background in separate div and the content in separate div. Both div shall have different z-index.

So it's code is like this:

<html>
<head>
<style>
#background{
position:fixed;
background:#c0c0c0;
opacity:0.2;
width:100%;
height:100%;
top:0;
left:0;
z-index:1;
}


#content-wrapper{
position:absolute;
z-index:2;
padding: 1em; 
max-width: 15em;
margin: 1em 10px; 
text-align: right;
}
</style>
</head>
<body>

<div id="background">
</div>
<div id="content-wrapper">

<h2>HANDMADE TIES</h2>
<p>DISCOVER NOW</p>


</div>


</body>
</html>
Varun Setia
  • 165
  • 1
  • 11