Ways to position text over an image and ensure that it adapts to different screen sizes

Hey there, I'm new to HTML and CSS and I've been trying to create a responsive landing page. I managed to display text on an image by adjusting the image's style to relative and the text's style to absolute. However, when I resize the site for mobile or tablet view, the text ends up going under the second image. I'm not sure where I might be going wrong here. Any guidance would be greatly appreciated.

Could you please suggest the best approach to displaying text on images while also ensuring the site remains responsive?

<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <img class="bg_image"  src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg">
            <h2 class="Lorem_Headding">Lorem ipsum </h2>
            <p class="p-text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam vulputate ut pharetra sit amet aliquam id diam. Tempor orci dapibus ultrices in iaculis nunc sed. Sit amet consectetur adipiscing elit pellentesque habitant morbi tristique.</p>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <img class="bg_image"  src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg">
            <h2 class="Lorem_Headding">Lorem ipsum </h2>
            <p class="p-text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Diam vulputate ut pharetra sit amet aliquam id diam. Tempor orci dapibus ultrices in iaculis nunc sed. Sit amet consectetur adipiscing elit pellentesque habitant morbi tristique.</p>
        </div>
    </div>
</div>


.bg-image { 
    position: relative; 
  }

.Lorem_Headding{
  position: absolute; 
  color: rgb(255, 255, 255);
  top: 200px; 
  left: 50px; 
  width: 100%;
}
.p-text{

    color: white;
    position: absolute; 
  top: 250px; 
  left: 50px; 
  width: 660px; 
}

Answer №1

The styling for .p-text does not require a specific width like 660px. Instead, the text should be wrapped within the div element. To enhance the user interface, consider adding margin and padding properties. For responsive design, utilize media queries to adjust layout for different screen widths.

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

What could be causing the issue with the JQuery .hide() function not functioning properly with the bootstrap spinner?

As I implement a basic spinner feedback for a server response to an ajax query, I encounter an issue. I utilize the JQuery .show() function before initiating the ajax call, and then invoke the .hide() function within the .always() callback of the request. ...

Invoking a URL asynchronously on a website

Unique Font License Dilemma Recently, I came across a unique situation with a font license that required me to query a counter on the font provider's domain every time the typeface was displayed. However, the recommended method of using import in the ...

Displaying text on top of an image with the help of jquery and

I found a tutorial on this website that I'm trying to follow. It involves creating a fading/darkening effect on image rollover with text appearing, but I can't seem to get it to work even when starting from scratch. Despite having experience wit ...

Using JavaScript to trigger an open dropdown menu in Bootstrap 4

I have a dropdown menu that is designed like this: <div id="actions" class="dropdown btn-group btn btn-outline-secondary" role="group"> <div id="actionToggle" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="fa ...

I recently aligned a component within a column of the Bootstrap grid using the <center> tag

Apologies for admitting this on Stackoverflow, but I'm struggling to center an element and the center tag seems to do the trick. My CSS skills are limited, so I'm reaching out to see if there's a better way to achieve this? <div class="c ...

Tips for validating a dynamically created form with Bootstrap tabs using jQuery

For my project, I am dynamically creating an HTML form using jQuery. The page consists of five tabs, each with separate previous and next buttons. These tabs are designed using Bootstrap. Can someone please suggest the easiest way to validate this page? Fo ...

What is the best way to extend an image to fill the width of a webpage?

Can you advise me on how to expand the image to fit the width of my webpage? If possible, could you take a look at this website: Poklanjam The specific image I am referring to is the one of the city on the left-hand side. What additional CSS code should ...

Function that activates traffic lights

Currently, I'm encountering errors while working on this project in Notepad. Can you help me figure out what's wrong with my code? I'm attempting to create an onload traffic light using an object array. The requirement is to implement this f ...

Using Slick Slider and Bootstrap CSS to display text on top of images

Currently, I am utilizing the slick slider from and I want to overlay text on top of the image. I tried using bootstrap carousel-caption, which works well with any image. However, with slick slider, it seems like the text is not at the highest level as I ...

Using *ngFor with a condition in Angular 4 to assign different values to ngModel

I am new to Angular 4 and encountering an issue with using *ngFor in conjunction with HTML drop-down select and option elements. My categories array-object looks like this - categories = [ { id:1, title: 'c/c++'}, { id:2, title: 'JavaScri ...

Creating a straightforward text/logo design for your HTML website?

After creating a standard website using HTML and PHP, I am now looking to add an exciting text/logo effect for when users first visit the site. Essentially, I want the logo to break apart and transition into loading the homepage once a user lands on the si ...

Implementing a SetTimeout Function in HTML

Is there a way to delay calling the mouseHoverTableRow() function until after hovering on tr for 3 seconds? I only want to call this function if the hover duration is at least 3 seconds, as it triggers an API request. How can I achieve this? <tr *ngF ...

Sending an email using Angular is a straightforward process that involves utilizing the built

I need help figuring out how to code a function in Angular or TypeScript that will open Gmail when a specific email address is clicked. I've tried different methods but haven't been successful so far. ...

Allow the width of the container to be determined by the img element

To achieve the desired effect of making the image resolution width dictate the container width without stretching it, I am facing a challenge. Currently, when the text within a paragraph element exceeds the width of the image, the entire container expands. ...

Can users be prevented from bookmarking a particular web page?

I'm working on a Python (Django) webpage and I need to prevent users from being able to bookmark a certain page. Is there a way to do this? ...

Where is the best location to store the image files?

I am currently working on a web application that focuses on Image processing, however I have encountered a basic issue. The images are not loading during the runtime of my HTML page. I have tried placing the image files in the src folder, but it seems li ...

Trigger fixed element to appear/disappear when scrolling using JavaScript

I've tried multiple solutions, but I can't seem to get this functionality to work properly on my website. I'm attempting to create a "schedule a demo" button similar to the one on www.bamboohr.com Currently, I have the following html, css, ...

Creating a unique paragraph style for my blog in SharePoint 2013 - step by step guide!

Managing a Share Point 2013 web site with a blog presents the challenge of incorporating special text content in posts. To ensure consistency, it's essential to add additional styles that can be applied to all posts. Normally, these styles are accesse ...

Steps to design a text div that extends beyond the bottom boundaries

Can anyone help me troubleshoot this design code using Bootstrap 3.x? Specifically, I am facing an issue with the following div. Any suggestions? Click here for more information. img{max-width:100%;} .mydiv{margin-bottom:20px;} .mytext{ positio ...

Manipulate a 3D shape by transforming both the x and y axes using jQuery's mousemove

I am trying to create a 3D element that rotates on both the x and y axes based on the position of the mouse on the screen. While I have successfully achieved this effect using either the X or Y position, I am struggling to make it work simultaneously for b ...