Tips for overlaying text on an image in html with the ability to zoom in/out and adjust resolution

My challenge is aligning text over an image so that they move together when zooming in or out. However, I am facing difficulties as the text and image seem to move in different directions. I have attempted using media queries and adjusting the positions of the containers with no success.

<div class="container-fluid test img-responsive">
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="text-center col-md-6 waben">
                            <img class="wabeeins pull-left img-responsive" src="https://i.ibb.co/f23d7qk/Artboard-1.png"
                                height="298.39" width="344.56" id="wabeone" alt=wabe1>
                            <div class="firsttext">
                                <h1>Test <br> test <br> test!</h1>
                            </div>
                        </div>          
                </div>
            </div>
        </div>
    </div>
</div>
</div>
@media (min-width: 1700px)
{
  .wabeeins{
    position: absolute;
    margin-top: 3%;
    margin-left: -8%;
    z-index: 5;
  }

  .firsttext {
    z-index: 10;
    position: absolute;
    margin-top: 12%;
    right: 32%;
    font-family: $font;
    color: $white;
    font-size: 30px;
    z-index: 100;
  }
}

I experimented without bootstrap and managed to somewhat solve the issue, but I am struggling to achieve the desired outcome with bootstrap.

My goal is to have the text and image move simultaneously in the same direction. Additionally, I aim to create a responsive layout for all resolutions, eliminating the need for individual @media queries (e.g., browser window resizing).

Answer №1

Make sure the parent div has a position of relative and the child div has a position of absolute. To center the child div, you can use the transform property. This code is designed to work for all resolutions.

HTML

<div class="container-fluid test img-responsive">
    <div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="text-center col-md-6 waben">
                            <img class="wabeeins pull-left img-responsive" src="https://i.ibb.co/f23d7qk/Artboard-1.png"
                                height="298.39" width="344.56" id="wabeone" alt=wabe1>
                            <div class="firsttext">
                                <h1>Test <br> test <br> test!</h1>
                            </div>
                        </div>          
                </div>
            </div>
        </div>
    </div>
</div>
</div>

css

.waben{
  position: relative;
  display: inline-block;
}
.firsttext{
  position: absolute;
  top:50%;
  left:50%;
  transform:translate(-50%, -50%);
  -webkit-transform:translate(-50%, -50%);
}
img{
  max-width:100%;
}

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

To ensure that new tabs are opened directly within jQuery UI tabs, the tab should be created within the jQuery UI tabs interface

I have integrated jquery-UI to create a dynamic Tab panel. When I click on the "Add Tab" button, a new tab is created. However, the new tab does not open automatically. It only opens when clicked on. $(function() { var tabTitle = $( ...

What is the method for selecting the desired month on a primeng calendar with multiple selection enabled?

I am looking for a solution to make my inline primeNg Calendar display the month of a specific date in the model, and when I remove dates from the model, I want it to show the current month. I have tried using defaultDate={{value}} and minDate={{value}}, a ...

Hovering over an option in Vue-Bootstrap b-select

I'm working with the Vue-Bootstrap framework and I need to update the CSS rule for the 'option' tag when it is being hovered over. Here is my code snippet: jsfiddle option:hover { background-color: red; } Can someone please explain why ...

Problem encountered when attempting to set and retain default values in a PHP select box

<form name="search" method="post" > Seach for: <input type="text" name="find" value="<?php echo (isset($_POST['find']) ? $_POST['find'] : ''); ?>" /> in <Select NAME="field"> <Option VALUE="catego ...

How to use CSS to dynamically adjust the maximum width of an overflow container based on its children's content

I have a container with an overflowing <div> that displays multiple <ul> <li> lists. Each list always contains the same number of bordered <li> items, resembling a table. However, there may be instances where a <ul> has only ...

conceal a div in Angular when the user is authenticated

One of my tasks involves managing the visibility of a div based on whether the user is logged in. This functionality is achieved by utilizing an authentication service in Angular and tokens from Django. Component.html <a *ngIf="authService.isLoggedIn( ...

Retrieving information from a JSON object in Angular using a specific key

After receiving JSON data from the server, I currently have a variable public checkId: any = 54 How can I extract the data corresponding to ID = 54 from the provided JSON below? I am specifically looking to extract the values associated with KEY 54 " ...

How can I create a redirect link in HTML that opens in a new window

I have a HTML page where I need to redirect to the next page. <a href="www.facebook.com" target="_blank">www.facebbok.com</a> Currently, it is redirecting to localhost:9000/dashboard/www.facebook.com But I only want to redirect to www.facebo ...

Running Protractor tests can be frustratingly sluggish and frequently result in timeouts

After spending most of the afternoon struggling with this test, I've tried different approaches but none seem to work. The task at hand is searching for users within the company, generating a table, and selecting the user that matches the name. Curren ...

Displaying HTML with extracted message form URL

I have a link that redirects to this page Is there a way for me to extract the message "Message Sent Successfully" from the URL and display it in the form below? <form action="send_form_email.php" name="contactForm" method="post"> //I want to d ...

Is there a way to execute a code snippet just once when focusing on a specific field?

<form id="myForm"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname"><br> <label for="mname">Middle name:</label> ...

All images must be arranged to fit seamlessly side by side regardless of the screen size

I'm currently experimenting with creating a website dedicated to my favorite TV shows. Upon entering the site, you are greeted with the main page that includes 7 images. Each image is linked to a specific webpage providing information about the corre ...

A fixed HTML div with a relative div is like having your own

I am in search of two divs with the following styles: <div style="height:20px;" /> <div style="height:100%;" /> These divs result in one being 20px tall and the other spanning 100% of the screen height, causing a vertical scrollbar that is eq ...

Verifying the current password and updating the hashed password

I have been struggling with creating a PHP script for updating user hashed passwords. Unfortunately, the script is not functioning as expected and no error messages are being displayed. Every time, it only shows "Your old password is incorrect" message. I ...

What could be causing me to have to click the button twice in order to view my dropdown list? Any suggestions on how to

I am facing an issue where I have to click twice on the "Action" button in order to see my dropdown list. How can I resolve this? Is there a way to fix it? $(document).ready(function() { $(".actionButton").click(function() { $dropdown = $("#cont ...

Encountered an issue while trying to install ngrx store with Angular 13 - unable to resolve the dependency

Encountering an error with the following command: ng add @ngrx/store@latest The error message reads as follows: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-prot ...

Testing the combination of Angular units with combineLatest

Recently, I delved into unit testing using the Jest Framework in Angular. However, I've encountered a roadblock while trying to write unit tests for the combineLatest RxJS operator. Check out my component below: Component: public userData; public pro ...

Inject parameter into MdDialog in Angular Material 2

I am currently utilizing Angular Material 2 and I have a requirement to display a dialog window using MdDialog that contains information about a user stored in Firebase. @Injectable() export class TweetService { dialogRef: MdDialogRef<TweetDialogCom ...

What causes the circular progress bar to disappear when hovering over the MUI React table?

My goal was to create a table with a CircularProgressBar that changes its background color from orange to dark blue when hovering over the row. However, despite my efforts, I couldn't get it to work as intended. Additionally, I wanted the progressBar ...

Testing Angular: Implementing Mock Classes and Services using the Any Data Type

When mocking services without using TestBed and instead relying on Fake Classes, is it considered a best practice to use a Mock with the : any data type? If not, errors like missing items/parameters may occur. Although spyOn can be used as an alternative, ...