Creating an opacity effect with CSS for circular images

My current challenge involves cropping an image into a circle, applying a gray filter, and overlaying text on top. The issue I'm facing is that the size of the circular clip-path changes based on the original image's dimensions due to user-uploaded profile pictures. This variability prevents me from properly applying the gray filter. Any suggestions on how to resolve this? Ultimately, I want the image on the right to appear as a circular grey-filtered image.

Explore the code on CodePen: https://codepen.io/dansbyt/pen/wvzyJzj

HTML:

<div class="center">
  <img class='pic large primary' src='../resources/pics/23.png'>
  <div class='picgroup large'>
    <div class='count'>+14</div>
    <img class='pic large secondary' src='../resources/pics/81.png'>
  </div>
</div>

CSS:

.pic {clip-path: circle();}
.primary {z-index: 3}
.secondary {z-index: 0; margin-left: -50px; margin-bottom: -30px}
.large.primary {width: 220px}
.large.secondary {width: 170px}
.small.primary {width: 150px}
.small.secondary {width: 116px}
.pic img{float:right; max-width: 100%; max-height: 100%; display: block;}

.center {
  display: flex;
  justify-content: center;
  align-items: center;}

.secondary img{object-fit: cover}

.picgroup {position: relative}
.small.picgroup:before {
  width:116px; height: 116px;
  margin-top: 20px;}
.large.picgroup:before {
  width:150%; height: 150%;
  margin-top: -30px;}
.picgroup:before {
  content:"";
  position: absolute;
  top:0; left:0;
  margin-left: -50px; 
  clip-path: circle();
  background: rgba(0,0,0,0.5);
  z-index: 2;
}

.picgroup .count {
  font-size: 50px;
  color: #E5E5E5;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-65%, -50%);
  z-index: 2;}

Answer №1

For achieving a color overlay effect, you can combine the brightness() and hue-rotate() rules within the .secondary class. See example below:

.secondary {
   ...
   filter: brightness(0.5) hue-rotate(90deg);
}

.pic {clip-path: circle();}
.primary {z-index: 3}

.secondary {z-index: 0; margin-left: -50px; margin-bottom: -30px;
filter: brightness(0.5) hue-rotate(90deg);
}

.large.primary {width: 220px}
.large.secondary {width: 170px}
.small.primary {width: 150px}
.small.secondary {width: 116px}
.pic img{float:right; max-width: 100%; max-height: 100%; display: block;}

.center {
  display: flex;
  justify-content: center;
  align-items: center;}

.secondary img{object-fit: cover}

.picgroup {position: relative}
.small.picgroup:before {
  width:116px; height: 116px;
  margin-top: 20px;}
  
/*.large.picgroup:before {
  width:150%; height: 150%;
  margin-top: -30px;}*/
  
.picgroup:before {
  content:"";
  position: absolute;
  top:0; left:0;
  margin-left: -50px; 
  clip-path: circle();
  background: rgba(0,0,0,0.5);
  z-index: 2;
}

.picgroup .count {
  font-size: 50px;
  color: #E5E5E5;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-65%, -50%);
  z-index: 2;}
<div class="center">
  <img class='pic large primary' src='https://mrdansby.com/resources/pics/23.png'>
  <div class='picgroup large'>
    <div class='count'>+14</div>
    <img class='pic large secondary' src='https://mrdansby.com/resources/pics/81.png'>
  </div>
</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

Exploring the contrasting behaviors of CSS in Codepen and Bootstrap

I am attempting to adjust the text to fit into divs of varying sizes that are responsive due to viewport units. There seems to be an issue: the code below works well in a Codepen, at least for the four examples I have: https://codepen.io/gramm/pen/VJPavg ...

Simple code in HTML and CSS to assign unique colors to individual characters of the text

What's the best way to assign a unique color to each character in a long text on an HTML page while keeping the file size of the generated HTML as small as possible? The goal is to use minimal color formatting tags. Any suggestions on how to achieve t ...

Modifying placeholder text styling using jQuery for font and color changes

I have a form with an input field like this: <input type="text" name="firstname" id="firstname" placeholder="First name"> Initially, I am checking if the input field is empty using jQuery: $("#submitreg").click(function(e){ if ($.trim($("#fi ...

Adding an image to an HTML page

I am working on an HTML page and need to insert an image. Here is the code I currently have: <img src="../Images/logo.jpg" alt="Logo" height="50"> I chose "../Images/logo.jpg" as the source because my logo.jpg is located two levels up from the curr ...

In Safari and Wamp, the PHP tag is often mistaken as a comment

Currently experimenting with PHP HTML in MAMP. When I insert the PHP tags <?php and ?> into my code, there seems to be a strange issue. Something is automatically changing them to <!--?php and ?-->, causing Safari to interpret it as comments. E ...

Customizing Semantic UI Navigation Menu Styles

For the first time, I am incorporating semantic-ui into my React application. The specific package I am working with can be found here: To display my header, I am using the following code: <Menu className='header' > <Containe ...

Confusion Arises When Joomla Buttons Clash

I am facing an issue with two modules on my website, each containing a button code. The code for the buttons is as follows: First Button <div onclick="parent.location='first-link'" data-mce-onclick=""><button class="button">First Bu ...

What is the best way to create a header that displays without the vertical scroll bar?

Is it foolish or out of the ordinary to ask a question without making an effort? I'm looking for a solution to have a header without a vertical scroll bar like in image 2 on the home page design. I want the top yellow header strip to be visible witho ...

Tips for styling custom buttons within the active editor popup of tinyMCE using CSS

Looking to enhance my tinyMCE active editor popup with custom CSS. Check out the screenshot provided for reference https://i.sstatic.net/vdVDF.png. Below you can find the code snippet used as a reference: tinymce.activeEditor.windowManager.open({ tit ...

`Cannot Get jQuery ScrollTop Function to Work for 2nd Element`

Having trouble with an issue. Let me explain. I implemented a scrollTop Jquery on page load that scrolls down after a delay to prompt user action. However, I'm facing a problem where another scrollTop doesn't work after clicking buttons "#b3,#b3 ...

Tips for ensuring the footer remains at the bottom of the page

I'm struggling with positioning my footer at the bottom of the page. No matter what I try, it just doesn't look right. Here's the code snippet I've been working with: <div id="footer"> <div class="container"> <div ...

How to use jQuery to dynamically set the value of a column span in a

Struggling with setting the value for a table column span. Here is my jQuery code: $('tr td data-th=Name span').val('My span content...'); This is how my HTML appears: <tr> <td data-th="Name"><span class="edit-inpu ...

What causes the styling to break in my CSS media query implementation?

Currently, I am working on making my sidebar fluid so that it adjusts with the browser window size. Everything seems to be going smoothly, except for one issue – when I add a media query to make it responsive, my CSS styling breaks. However, if I remove ...

Trigger an instantaneous update of the masonry grid

My website currently utilizes a script that generates a grid, and the grid elements are automatically adjusted each time the width of the viewport is modified. Although I do not have access to or control over the script since I did not write it myself, I s ...

Looking to generate flipcards dynamically through javascript or jquery when a button or link is clicked?

I've created flipping cards that flip on hover, but I'm struggling to add a button/link that generates a new flipcard when clicked. Any help would be greatly appreciated - plus, I'm new here! Here's my HTML and CSS code for the flipcard ...

Troubleshooting: Django project not functioning properly post transfer from Windows to Mac

Using Django 3.1.7 on a MacBook Pro now, I recently moved the Django project from a Windows 10 machine. Despite setting up the database and superuser again, running pipenv sync didn't result in serving any of my URLs or Admin page CSS styles. The serv ...

Unable to locate the module specifier "three". Relative references must begin with either "/", "./", or "../"

I am currently facing an issue while attempting to load a .obj model into my three.js project. Despite having what I believe to be the correct code (as it compiles without any errors), there is an error showing up in Google Chrome's console. The error ...

Position the iframe at the center of the image for the best display

I'm looking for a way to make my web app appear as if it is on an Android or iPhone device. I've explored various solutions, but they all have their drawbacks. My workaround involves loading the web app in the middle of an iframe, which is then p ...

Add up the values in the table by organizing them into groups

There is a table below that I am working with: <table> <tr> <th>Category</th> <th>Value</th> </tr> <tr> <td class="cat1">cat1</td> <td class="value" ...

Customize the pop-up on a cell within a table based on its specific

I am currently in the process of building a website using Flask that showcases a data table with abbreviated codes for certain values. My main objective is to implement popovers on these cells to display the full meaning when hovered over. For example, the ...