Text appearing against a background with a see-through effect

Is there a way to show text with a transparent background color over another background image or text?

I am looking to include text over existing text

Answer №1

Is this what you had in mind? The key technique here involves using rgba for the background-color, with the opacity (alpha channel) specified as the last parameter.

.container {
  position: relative;
  text-align: center;
  color: white;
  width:300px;
}

.container__image{
  width:100%;
}

.container__text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size:26px;
  color:red;
  background-color: rgba(0, 0, 0, 0.5);
}
<div class="container">
  <img src="https://picsum.photos/300/300" class="container__image"/>
  <span class="container__text">Some text</span>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to make a <div> load automatically when the page starts loading?

I'm having an issue with my code where both <div> elements run together when I refresh the page. I want them to display separately when each radio button is clicked. <input type="radio" name="cardType" id="one" class="css-checkbox" value="db ...

Ensuring the dropdown menu's functionality in AngularJS

I'm currently working on a code snippet that validates when the user moves away from a specific select element. The goal is to change the border color of the select element to either red or green only when the user tabs away from it or moves the mouse ...

Issue with Displaying Full-Page Div

My HTML page consists of just one div. The body code is as follows: <div> </div> Here is the corresponding CSS: body { margin:0; height:100vh; width:100vh; } div { height:100vh; width:100vh; color:#000000; } I c ...

Guide to connecting a different HTML page to a thumbnail image using jQuery

let newColumnBlock = $('<div class="col-md-2">'); let newImagePoster = $('<img>'); let newSelectButton = $('<a href="secondPage.html"><button class="selectButton"></button></a>'); let movie ...

Using Bootstrap in Rails: Positioning a dropup to align with another element in a footer

I am attempting to align the content as a footer, but having trouble with the dropup not lining up properly: <footer class="footer"> <div class="container-fluid"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-12"> &l ...

Inconsistencies in table row border behavior

I created a table that allows users to set a marker on a specific row by adding a 5px border to the left side of the row. Interestingly, when the border is added to the first row, the table gets padded on the right by a few pixels. However, this padding d ...

Struggling to align the search box in the center of the Bootstrap navbar

I'm currently working with a static bootstrap navbar and trying to center a search box within it. Unfortunately, all my attempts have been unsuccessful so far. The search box either appears below the navbar or doesn't display at all. At this poin ...

Text stretched to its fullest height and rotated using the transform property

check out the demo Here is a demonstration of HTML elements: <div class="controller"> <div><a href="#buttton-1">Special Offer</a></div> </div> And here is the styled CSS for the demo: .controller{ width: 55px; ...

Extract the content of a textbox within an iframe located in the parent window

Is it possible to retrieve the value of a text box in an iframe from the parent page upon clicking a button? Below is an example code snippet showcasing the situation: <div> <iframe src="test.html" > <input type=text id="parent_text"> & ...

Aligning a left-aligned span with inline input buttons while floating to the right

I am struggling with aligning buttons to the right side of a div while keeping everything displayed in line. Currently, the buttons appear below the span rather than beside it. I have attempted setting the button's display to "inline" and "inline-bloc ...

Unable to load circles on page refresh with amCharts Maps

I am experiencing an issue with the functionality of my amCharts maps. Whenever I refresh the page, the circles that are supposed to be displayed disappear. However, when I zoom in, the circles reappear. This problem has me puzzled, and I'm not sure ...

Center the content within a div by utilizing either the auto or percentage values

Hey there, I'm currently facing some issues that I can't seem to solve. I've tried various solutions but none of them are working for me. My goal is to center the content of one div inside another. I prefer using only auto or % values as I ...

"How to Align Sliding Images in the Center Across Various Web Browsers

I am trying to adjust the sliding image on my webpage's page banner so that it appears in the center instead of floating to the left or right. Here is the HTML code: <ul class"rslides" id="slides"> <li><img src"image/test.jpg">&l ...

Using Jquery, update the class toggle to apply to multiple span elements instead

I am facing an issue where I need to change the class of a span child using a toggle feature when clicking on a browser row. The problem arises when there are multiple rows, as the span cannot be found and the functionality does not work properly. I have ...

Encountering an issue with Angular routing: Cross-origin requests are restricted to specific protocol schemes, such as HTTP

I encountered an error while working on angular routing. Below is my HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <script src= ...

The validation of radio input signals results in an error being returned

For a while now, I've been trying to solve the issue with radio button validation in my current project. Surprisingly, it works fine when there are no other functions in the form besides the radio buttons themselves. I suspect that the problem lies wi ...

What is the best way to ensure both landscape and portrait images are completely responsive and equal in height within a carousel?

I am currently working with a bootstrap carousel that contains both portrait and landscape images. On wide screens, the carousel height is automatically set to match the tallest image's height. However, this behavior results in white spaces on the top ...

Exploring AngularJS: Implementing CSS media query for responsive screen resizing

I currently have a CSS code that triggers a message box through media query when the screen is resized to a specific size. I am looking for a way to make the message box disappear automatically after 5 seconds. Do you have any suggestions on how to achiev ...

What is the best way to showcase images in a horizontal layout with the help of PHP and

Does anyone know how to retrieve images from a MySQL database and display them in rows of three horizontally, while also having a relevant image show on top? I'm struggling with this task. Below is the code snippet for the main div: <div class="co ...

parsing the data from an HTML document containing embedded variables

Is there a more efficient way to use file_get_contents() on an html file containing 3 variables and have those variables populated with data from $_POST? For example: -html file- <html> . . <table> <tr> <td> ...