How can I overlay text on top of an image?

I want to create a design where half of the text overflows and overlays the image on the right side. How can I achieve this using a Grid item? I've tried using "absolute", "relative", and "z-index" positions, but they don't seem to work in the MUI context. What would be the best approach for this? Thank you in advance.

code

import React, { useState } from 'react';
import './../App.css';
import {Grid, Typography, Paper, useMediaQuery, useTheme, Container, CardMedia} from '@material-ui/core';
import {makeStyles} from '@material-ui/core/styles';

const useStyles = makeStyles((theme) => ({
  imgSpacing: {
    marginLeft: '20px'
},
  holder: {
    display: 'flex'
},
  holderText: {

},
  holderImg: {
    flexGrow: '1'
}
}))

function Homepage() {
  const classes = useStyles();
    return (
      <div>
        <section>

          <Container maxWidth={false} className={classes.img}>
            <Grid item xs={12} container>
              <Grid item xs={2} />
              <Grid item xs={5}>
                
                <div className={classes.holder}>
                  <div className={classes.holderText}>
                    <Typography >
                        <h1>
                        Lorem ipsum dolor sit amet.
                        </h1>
                        <p>
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
                        </p>
                    </Typography>
                  </div>

                  <div className={classes.holderImg}>
                    <Paper >
                        <CardMedia
                          component="img"
                          image={require(`../images/LA_night_car.jpg`)}
                        />
                    </Paper>
                  </div>
                </div>

              </Grid>
              <Grid item xs={2}>
                <Paper className={classes.imgSpacing}>
                    <CardMedia
                      component="img"
                      image={require(`../images/skater.jpg`)}
                    />
                </Paper>
              </Grid>
              <Grid item xs={3} />
           </Grid>
          </Container>
        </section>
      </div>
    );
}

export default Homepage;

image for reference https://i.stack.imgur.com/0PBBv.png

Answer №1

When text overflows onto an image, it creates a unique composite element that blurs the line between text and image. It deserves its own designation, such as HomepageHeadliner (although ideally tailored to your specific domain).

Place these elements into this container and utilize absolute positioning based on your rationale. If the text precedes the image in the DOM tree, z-index should not be necessary.

Answer №2

To create a visually appealing text box, you can utilize a Box element and apply background properties to it. Embed any desired typography text within the box like shown below:

<Box
          sx={{
            background: `url('/img/baner.svg')`,
            backgroundSize: "733px 240px",
            height: 240,
            width: "auto",
          }}
        >
     <Typography
          variant="inherit"
          fontSize="110%"
        >
          Custom Text Here
        </Typography>
 </Box>

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

Tips on altering the quantity of columns in a ul list dynamically

I'm trying to create a list with 2 columns, and I want it to switch to 3 columns when the browser window is wide enough (for example, on a 23 inch monitor). Can this be achieved using CSS or any other method? Here is my current CSS: .search-results ...

Material-UI X-Grid encounters a resizing columns issue when utilized in RTL mode

When using the Material UI X-Grid component with an RTL theme, there seems to be an issue with resizing columns. When attempting to expand a column by dragging the left portion of the column separator to the left, it actually shrinks instead. This unexpect ...

Navigating through sibling elements can be accomplished by using various methods in

Can someone help me figure out how to assign unique IDs to 6 different Div elements as I step through them? The code snippet below is not working as expected, giving all Divs the same ID. What is the correct way to accomplish this task? $('#main-slid ...

Step-by-step Guide on Updating the State of Multiple Chip Values in a React Material UI Autocomplete Component

Working on creating a custom function for React Material UI Autocomplete. I have referred to this documentation: https://mui.com/material-ui/react-autocomplete/ The goal is to enable users to select multiple values from the autocomplete list, displayed a ...

What is the material-ui component that mirrors the functionality of <input type="color"><datalist>?

I'm just starting out with javascript, react, and Material-UI, so my question (along with the code sample) might show my lack of experience. Within a Material-UI TableCell (not a form), I have the following code: <input type="color" name ...

Is your Javascript navigation functioning properly on some submenus while encountering issues on others?

If you visit , you'll notice that it's a visually appealing site. The navigation submenus seem to be functioning properly, HOWEVER upon inspecting the element, you'll notice that under the PRICING tab, there are submenus that have the same c ...

Submitting a form via email without the need for PHP

Currently, I am focusing on a project that is small and emphasizes presentation more than security. The main objective is to create a form where users can input data, then click submit for all the information gathered to be sent to a specified 'mailt ...

Achieving the perfect horizontal alignment of images

Currently working on a new project and here's the page I'm focusing on: The elements are exceeding the set height of their container and overlapping into the content area instead of pushing the existing content down. Any suggestions to fix this ...

Imagine a webpage with a width of 1000 pixels. Can you determine the precise horizontal position (from the left) of the div element with the unique id of "inner_div"?

Hello everyone, I hope you're doing well. I recently took a test and unfortunately got this question wrong. Imagine a web page with a width of 1000px. What is the exact horizontal (from the left) position of the div element with id "inner_div"? < ...

Enhance your webpage with dynamic styling using third-party CSS animation

Apologies for any similarity to other questions on this topic. I have searched extensively, but any assistance would be greatly appreciated. I am utilizing a new animation library from Animista to animate specific elements on a test website. Animating ele ...

Mixing Module Federation with different React versions and individual CSS isolation

In my setup, the module federation remote repository is: developed using react 17 utilizing material-ui 4 with jss incorporating global CSS from third-party libraries that cannot be modified Meanwhile, I have several hosts that consist of: different ver ...

Create dynamic animations on HTML text using CSS

Looking to add some flair to your website with a text animation? How about making the text automatically glide from one side to the other like a ticker display? Any suggestions for simple CSS code to achieve this would be greatly appreciated! Thanks in ad ...

I am experiencing difficulty transitioning the view in React Native from a side position to an inward direction

Currently tackling a design project and encountering a roadblock in achieving a specific curved effect. Here are two images for reference: The Desired Design: My Current Progress: The basic structure is in place, but hitting a wall when attempting to cu ...

Height and placeholder issue with ion-searchbar

Hey there, I hope everything is going well for you. I've encountered a problem with the Ionic 5 - Angular Searchbar feature. This is how I added the searchbar: <ion-searchbar [(ngModel)]="text" (ionChange)="sear ...

Tips for utilizing an adaptive design with Angular

I am working on designing a page that allows for scrolling if needed. On each section of the page, I will be incorporating specific components with unique colors to enhance the layout. However, my current HTML code is not producing the desired result as sh ...

Expand the container as the child element grows using flexbox

Check out this layout: <div class="wrapper"> <div class="middleman"> <div class="inner-child"> /* Child with the ability to expand height */ </div> </div> </div> Imagine the wrapper has an initial hei ...

Material Ui Grid does not resize correctly

I'm currently struggling with achieving the desired Grid responsiveness on my website. The idea is to display all 6 columns next to each other in full screen mode, then adjust to 3 columns on smaller screens with another 3 columns below them. It looks ...

Trouble with jQuery addClass function when trying to add to a specific object variable

I'm attempting to give an error class to an input textbox to inform the user that their input is invalid. Within the change event, I am referencing what seems to be the input field and storing it in a variable. However, calling addClass on the var ...

Tips for eliminating the ripple effect when clicking on a q-list item

I have managed to create a sleek sidebar with a curved edge that seamlessly integrates into the body of the page. However, I am struggling to remove the semi-transparent ripple effect that appears when clicking on a list item. The current effect clashes ...

What is the best way to eliminate the gap between header, content, and footer sections when in mobile view?

This issue seems to only occur in mobile mode, where the blueviolet line is coming from the background color. https://i.stack.imgur.com/VBhIp.png link to the image body { background-color: blueviolet; } header, main, footer { background-color: #ff ...