If you're looking to enhance your design, you have a couple of options to consider. One is to follow Lee's advice and perhaps include some padding for added visual appeal. Another option is to utilize the text-shadow property in CSS.
div {
width: 100px;
height: 100px;
margin: 20px;
text-align: center;
line-height: 100px;
color: white;
text-shadow: 0 1px black;
}
.dark {
background: #333;
}
.light {
background: #ccc;
}
<div class="dark">Some text</div>
<div class="light">Some text</div>
You also have the option to combine both approaches mentioned above for a unique result.
div {
width: 100px;
height: 100px;
margin: 20px;
text-align: center;
line-height: 100px;
}
.dark {
background: #333;
}
.light {
background: #ccc;
}
span {
color: white;
text-shadow: 0 1px black;
background: #333;
background: rgba(0, 0, 0, 0.18);
padding: 4px 8px;
}
<div class="dark"><span>Some text</span></div>
<div class="light"><span>Some text</span></div>
The issue with adjusting the opacity directly is that it affects both the background and the content within. In contrast, using RGBA values allows you to specify transparency without impacting the text inside the element. By incorporating RGB color values with an alpha layer component, you can control the opacity of the background separately from the text.
To achieve this effect, simply append the desired opacity value (e.g., 0.8) after the RGB color values in the format rgba(red, green, blue, alpha). This approach maintains the text at full opacity while adjusting the background transparency accordingly. Check out the examples provided above for more clarity on how to implement this technique in your projects.