Changing the transparency of text alters the appearance of the background color

I am trying to create a unique transparent button with an icon or text inside, that changes its appearance on hover by making the text transparent and the background colored. Here is a snippet of my code:

.button-color {
  padding: 12px 20px;
  border: none;
  color: red;
  background-color: transparent;
}
.button-color:hover {
  color: transparent;
  background-color: red;
}
<button class="button-color">Hi!</button>

(The actual code is more extensive but this illustrates the concept) And here is how it looks:

Unhovered:

https://i.sstatic.net/2gPqH.png

Hovered:

https://i.sstatic.net/UHWSt.png

I would like the background to remain transparent where the icon is located. Considering the buttons are within a 3D viewer with a loaded model, simply setting the icon to a specific color won't resolve the issue. I'm uncertain if achieving this effect solely with CSS is possible, but one can hope.

Answer №1

To achieve this particular effect, you can utilize the blend-mode property with hard-light as long as the element's color is either 0 or 255, representing primary colors.

When utilizing this blend mode, a color of gray (RGB values of 128) behaves as "transparent."

.button-color {
  padding: 12px 20px;
  border: none;
  font-size: 100px;
  color: red;
  background-color: gray;
  mix-blend-mode: hard-light;
  left: 10px;
  top: 10px;
  width: 200px;
}
.button-color:hover {
  color: gray;
  background-color: red;
}

.container {
    background-color: lightgreen;
    width: 200px;
}
<div class="container">
<button class="button-color">Hi!</button>
</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

Calculate the sum of floating point or decimal numbers from a textarea using JavaScript

I'm trying to work with a text area that contains decimal/float numbers. However, the code I found online seems to be ignoring commas and periods when summing up the values. Is there a way to handle decimal/float numbers correctly in this scenario? ...

wrap text image not compatible with responsive layout

Plunker Link: https://plnkr.co/edit/kC9SPK2e7iy5OYhKpwOO?p=preview <html> <head> <link data-require="bootstrap@*" data-semver="4.1.3" rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" /> ...

How can I prevent Hover effects on active LI elements in a menu?

When a Navigation menu item (LI) is marked as active in CSS, how can I prevent it from being hover-able? Check out the CSS code below: .page-header .menu li { float:left; display: inline; margin-right: 2px; line-height: 34px; } .page-he ...

Ways to eliminate the white overlay that occurs on the page after clicking the scroll top button

Hi there! I've been busy with updating my site at , and noticed a small glitch. Every time I hit the Back to Top button at the bottom of the page, the screen goes white. Any ideas on how to fix this issue? Thanks in advance! ...

Aligning Text and images perfectly in a DIV container, and beyond

I am trying to center or align text and images at the bottom of a couple of tags, but vertical-align doesn't seem to be cooperating. Another challenge I have is creating a horizontal menu with a start image (e.g. menutop.png), followed by a filler ( ...

Trouble aligning text next to boxes in Bootstrap Modal

Having trouble aligning the input text boxes in a modal form created with Bootstrap? The fields are currently showing under the labels instead of beside them. Looking for suggestions on how to fix this alignment issue. <button type="button" class= ...

Designing an interactive region using HTML, CSS, and JavaScript

I recently created this code with some assistance: When I tried to format the code, it all ended up on one line and looked unreadable. To view the code properly, please visit this link: http://jsfiddle.net/QFF4x/ <div style="border:1px solid black;" ...

Adding a sibling inline can be accomplished by simply using the "+"

$("#sibling").prepend("#sibling2") <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sibling">First sibling</div> <div>Another component</div> <div id="sibling2">Seco ...

CSS: Creating a block that stretches the entire width of its parent block

I've been facing the same issue multiple times. Whenever I use the float property to display one block, the next block ends up overlapping with the first one. For example: Consider the following block of code: .row_item{ width: 30%; display: block; ...

php log in button with a redirect feature

As a complete beginner, I created a basic login.php. However, I am unsure how to make the login button redirect to another page. Below is the script I currently have: <php //Initiate the Session session_start(); require('connect.php'); ...

JQuery is having trouble with playing multiple sound files or causing delays with events

I've been working on a project that involves playing sounds for each letter in a list of text. However, I'm encountering an issue where only the last sound file is played instead of looping through every element. I've attempted to delay the ...

The use of "runat="server" in the HTML Head tag is preventing C# embedded code blocks from being converted to client-side code

After I included runat="server" in the head tag and added a CSS href with the value of <%= WebAppInstance %>, I noticed that the <%= WebAppInstance %> was not being converted to client-side code. To provide clarity on my question, please refer ...

Displaying an error or success message upon submitting a form is currently not functioning as

I have implemented a registration/login system on my website, and currently, it shows errors and success messages at the top of the page. I want to display these messages under the form instead. However, every time I attempt to place them below the form, i ...

The picture is malfunctioning

I am experiencing an issue with the placement of an image in my HTML code. When I place the image inside the nav element, it works perfectly fine. However, when I try to put it inside the body or header elements, it doesn't display properly. I am new ...

Ensure that the heights of various Flexbox rows are always visible within the boundaries of the browser window

Within flexbox, I've laid out three rows of boxes with varying heights. This layout ensures that the rows always align perfectly with the bottom of the browser window without any gaps. You can see the full layout on Codepen by following this link: htt ...

Any tips on how to personalize the loading animation for single pages using CSS and GIFs?

presentLoading(message) { this.loading = this.loadingCtrl.create({ dismissOnPageChange: false, spinner:'hide', content:`<img class="load" src="assets/dual.gif" />`, }); this.loading.present(); } Hello there! I am working with the ...

The functionality of Bootstrap 5's modal-dialog-scrollable seems to be malfunctioning

I recently created a Student Add form using bootstrap 5 <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dial ...

Remove a row from the database with PHP by utilizing an HTML table

I'm having trouble with the "delete" function in my form. Even after trying this code: while($row = $result->fetch_assoc()) { $ordernr = $row['ordernr']; $klantnaam = $row['klantnaam']; $productnaam = ...

Placing a div above the navigation bar in jQuery Mobile to create multiple stacked footers

I am currently facing an issue with my website where I have a static nav bar at the bottom of each page, but I need to add another content div above it. When I try to position it as a footer, it ends up in the same spot as the nav bar. Absolute positioning ...

How can one iterate through elements of a specified length using Jquery?

Currently, I am in the process of designing an animation for my website. The animation involves different divs that each contain an image and a description related to that image within an aside element. The width of the aside is slightly wider than the ima ...