Ways to achieve an arched shadow effect for an image using React and Tailwind CSS?

Looking to add a unique touch to my React project with a shadow effect resembling an arch shape at the top of an image using Tailwind CSS. The ultimate goal is to create a semi-transparent arch-shaped shadow covering the top portion of the image, similar to the example image provided.

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

Here's what I've attempted thus far:

.arch-shadow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 100% 100% 0 0;
  z-index: 1;
}

<div ref={viewRef} className="w-full relative flex justify-center">
  <CardImgFrame
    imageUrl={imageUrl}
    alt={title}
    frameClassName="aspect-4/5 h-[516px] relative z-10"
    imageClassName="object-fill"
    priority={true}
  />
  <div className="arch-shadow"></div>
  {description && (
    <p className="absolute text-white bottom-3 font-semibold z-20">
      {title}
    </p>
  )}
</div>

The objective is to have a semi-transparent arch-shaped shadow covering the top part of the image, providing a unique shadow overlay effect with an arch shape at the top.

Current implementation either covers the entire image or fails to achieve the desired arch-shaped effect at the top of the image.

Answer №1

To create a unique visual effect, consider using the arch as the background for the pseudo-element located within a parent container. Utilize radial gradients and clip-path to transform the arch into a semi-circle shape.

Take a look at this straightforward example:

<style>
  * {
    margin: 0;
  }
  
  div {
    width: 100vw;
    height: 100vh;
    background-image: url(https://example.com/image.jpg);
    background-size: cover;
    position: relative;
  }
  
  div::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    aspect-ratio: 1;
    opacity: 0.3;
    background-image: radial-gradient(circle at 50% 50%, transparent 0 70%, gray 70% 100%);
    clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%);
  }
</style>
<div></div>

Keep in mind that you may need to consider how the design adapts when the viewport changes its aspect ratio, particularly in landscape orientation. Ensure that the semi-circle remains appropriately positioned to showcase the underlying image effectively.

Answer №2

It appears that you are heading in the right direction, but there may be some adjustments needed in the CSS to ensure that the shadow is covering the top of the image accurately. You can try the following code to achieve the desired result.

.arch-shadow {  
  position: absolute;  
  top: 0; /* Positioned at the top */  
  left: 0;  
  right: 0;  
  height: 50%; /* You can modify this height as needed */  
  background: rgba(0, 0, 0, 0.5);  
  border-radius: 50%; /* Creating a circular top arc */  
  transform: translateY(-50%); /* Moving it upwards to overlap the image */  
  z-index: 1; /* Ensure it is above the image but below the title */  
} 

To integrate everything into your React component, you can use the following code:

const ImageWithArchShadow = ({ imageUrl, title, description }) => {  
  return (  
    <div className="relative flex justify-center w-full">  
      <CardImgFrame  
        imageUrl={imageUrl}  
        alt={title}  
        frameClassName="aspect-4/5 h-[516px] relative z-10 overflow-visible" // Ensure overflow is visible  
        imageClassName="object-fill"  
        priority={true}  
      />  
      <div className="arch-shadow"></div>  
      {description && (  
        <p className="absolute text-white bottom-3 font-semibold z-20">  
          {title}  
        </p>  
      )}  
    </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

Adjustable Greybox Overlay Resizes Window Dimensions

Utilizing greybox on my business website allows users to easily log in and access their accounts. View an example of my site However, when the login or sign up window is activated at the top of the page, the page or window size changes, causing scroll bar ...

Initiate requests to external servers from a NodeJS backend

My NextJS application seamlessly collaborates with a NodeJS server to act as the front end of my innovative three-tier architecture. 'use client'; import FormControl from '@mui/material/FormControl'; import InputLabel from '@mui/m ...

Preserve a data point without causing any alterations

I am working with a device that continuously sends values until it is stopped. These values are then saved inside an array. deviceMonitoring( device2 ){ // In this function, I populate the arrayTimestamp and then copy the first value. this.arrayElement = t ...

Printing Apex Oracle reports using Internet Explorer

I am facing a challenge with printing my page that contains two interactive reports. To enable printing, I have utilized a JavaScript function that triggers window.print(). I have incorporated CSS to adjust the layout of my tables when printed. @media pr ...

Unable to accommodate additional space, InputGroup is not utilizing the

Using react-bootstrap in my project, I have a component with the following code. I want the input and button to display together and fill up the entire space allocated by the Col. Although the input and button are displaying side by side, they are not ta ...

"Seamless integration: Enhancing communication between NextJS application and Express server through internal API

Currently, I have a NextJS application implemented with a custom express server. Within my pages/index.js file, I am making an internal request to the express route /api/users using isomorphic-unfetch within the getinitialprops() function as shown below: ...

Adding two BR tags between inline images within a wrapper is causing inconsistencies in spacing when viewed in Firefox compared to all other browsers. Check out an example of this issue in

JS Fiddle Link http://jsfiddle.net/Xfvpu/1/ Having a perplexing issue with image rendering in Firefox compared to other browsers. The xhtml doctype is used with proper br / tag spacing, but the gap between two images on this specific document displays dif ...

Apollo's useQuery executes just once and doesn't run again when components are re-rendered

Recently diving into the world of GraphQL and nextJS, I find myself facing a challenge in my ongoing project. My goal is to fetch data from the GraphQL server only once and then have that same data persist throughout multiple component re-renders. I atte ...

Is it possible to use negative values in css?

Is it acceptable to utilize negative values in CSS? For instance: margin:-11px 20px -18px 0px; OR Is there a prevailing guideline that prohibits the use of negative values? ...

Tips for creating a mobile-friendly 30-day chart with chart.js

I created a chart displaying 30 days of absence data using the react-chartjs-2 library, but it is not responsive. How can I make it responsive? Here's how it appears on a laptop: chart on laptop And this is how it looks on mobile: chart on mobile T ...

discovered a total of 63 minor vulnerabilities during the npm dependencies installation process

pm WARN [email protected] is in need of typescript@* as a peer dependency, however it has not been installed. It is necessary to manually install the required peer dependencies. ...

Here's a way to align big text in the center while aligning small text at the bottom

How can I position two text blocks on the same line in HTML, with one text block having a larger font size and vertically aligned in the middle, while the other text block sits lower to create a cohesive design? To better illustrate what I mean, I have cre ...

The JSX element 'body' appears to be missing its closing tag

I'm currently in the process of developing a landing page using react.js. This particular page is designed for users who are not yet signed up to create an account if they wish to do so. Unfortunately, I'm encountering some errors, one of which p ...

Steps for turning off directory listing on a Next.js site hosted on Vercel

After deploying my website built with Next.js, I realized that all the static files and resources were located in a single directory, which does not sit well with me. The directory structure looks like this: mydomain.com/_next/static, or in my case, http ...

Distinct styling for the start and subsequent lines of an anchor element using ::before pseudo-element

I'm currently working on a project that requires adding a decoration in front of some anchor links (A). Right now, I am using ::before to achieve this. However, there is an issue where some of the links will line-break and the second line and subseque ...

setting a div element to occupy a percentage of the window's height using viewport height units (vh) within the Wordpress platform

this is the desired appearance but upon pasting the identical code: <!-- placeholder div --> <div style="height:100px;"> </div> <!-- outer container div (with specified height) --> <div style="height:80vh;"& ...

The transformation rotation applied in CSS must not have any impact on the styling of my span and paragraph

Snippet: .details-section{ background-color: rgb(83, 83, 83); height: 200px; } .icon-container{ border: 2px solid #c49b63; width: 90px; height: 90px; transition: 0.5s ease; } .box i{ font-size: 60px; color: black; margin-top: 13px ...

Modal window closed - back to the top of the page

I am struggling with a simple modal popup window that does not maintain the scroll position when closed, instead returning you to the top of the page. I am looking for a way to keep it at the same scroll position without much knowledge of Javascript. You ...

Solving cross-origin complications with React and Express API

Encountering an issue with a React contact form connected to an Express API via Node, every time I attempt to submit the form, I am faced with this error message: Access to XMLHttpRequest at 'localhost:4000/api/v1/' from origin 'http://loca ...

Having trouble with React Page crashing when trying to access the component state

I'm attempting to create a side-bar menu that swaps out content in a <main> tag when menu buttons are clicked. However, I'm facing an issue where the page becomes unresponsive and eventually crashes due to React issues while trying to read ...