Tips for aligning multiline text in the center of images with varying widths

Excuse my lack of experience, but I have a question,

I am looking to center a header and some text next to an image with variable width. Additionally, the text should be able to position on either side of the image, while still being coded first in the HTML (for mobile display purposes using media query).

I've experimented with using display:table, but it seems to conflict when floating the image.

I could potentially use PHP in Wordpress to set the width of the text div dynamically based on the page width and image width, but I'm hoping for a more elegant solution.

    <!-- text left-->
    <div class="l">
        <div class="td">
            <h2>History</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, excepturi, tenetur deleniti nemo animi repudiandae. Soluta, quia quod magnam nobis!</p>
        </div>
        <div class="">
            <img src="images/History.jpg"  alt="Our History"><!-- class="img-responsive" -->
            <div style="clear: both;"></div>
        </div>
    </div> 
    <!-- text right-->
    <div class="r">
        <div class="td">
            <h2>History</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, excepturi, tenetur deleniti nemo animi repudiandae. ...</p>
        </div>
        <div class="">
            <img src="images/History.jpg"  alt="Our History">
        </div>
    </div>

CSS:

* {
box-sizing:border-box;
}

.l,.r {
/*  display: table;  */
    width:100%;
/* height: 421px; */
}

.l .td {
    width:38%;
    float:left;
    position:absolute;
    top:50%;
/*  height: 421px; */
    margin-top:-100px;
/*  float:left; */
/*
    display: table-cell;
        display:table-cell!important;
    vertical-align:middle;
*/
/*  float:none; */
}

.l img {
    float:right;
    width:62%;
}

.r,.l {
    position:relative;
}

.r .td {
    width:38%;
    position:absolute;
    top:50%;
    height:60%;
    margin-top:-100px;
    right:0;
}

.r img {
    width:62%;
}

.l .td,.r .td {
    padding-left:5%;
    padding-right:5%;
    max-height:100%;
    overflow:auto;
}

Answer №1

hopefully this information is useful

consider incorporating some CSS styling,

.test1 txtWhiteBg col-xs-12 {
    margin-top:-200px; //customizable based on your image dimensions
  }

<div class="row ">
   <div class="test2 noLRPadding col-xs-12">
      <img src="images/History.jpg"  alt="Our History"><!-- class="img-responsive" -->
   </div>
   <div class="test1 txtWhiteBg col-xs-12">
      <h2>History</h2>
      <p>Lorem ipsum dolor sit amet, consectetur a!</p>
   </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

The scrollbar is failing to display the entire content on the right side of the HTML document

I am facing an issue with creating a horizontal scroll bar within a div element that contains all the contents. The problem arises when a user scrolls, as it is not fully scrolled to the end of the right side, making it impossible to see the content at the ...

How to Change the Start Time of a Live Broadcast using PHP with Youtube API

I have successfully created broadcast events in YouTube Live, but I am now facing a challenge while trying to update existing events using the update API. The issue lies with the VideoSnippet library, as it does not support this functionality and requires ...

Utilizing WebIOPi in Your Current Website

I'm currently navigating the complexities of WebIOPi and struggling to integrate it into my project. Here's some background information: I am utilizing a Raspberry Pi B+ with Wheezy installed. My focus is on developing a web-based application th ...

Tips for choosing the dropdown selection on an ASPX website page

I have a specific dropdown menu set up, and I need to select the appropriate option from the viewdata object in my .aspx page. Here is what my menu looks like: <td headers="Vehicle" style="background-color:#EFF3FB;font-family: Verdana; font-size: 10px ...

Manipulating toggle buttons using CSS and jQuery

Check out this jsfiddle to see my attempt at creating a toggle switch in the form of a mute button. The toggle button shows the current setting: mute or unmute When hovered over, it displays the alternative setting However, I am encountering an issue wh ...

Customized Quick Access MUI

Hey there! I'm currently working with the Speed ​​dial component for MUI and I'm having trouble figuring out how to style the tooltipTytle. I can only seem to style them when they are all displayed at once, but that's not what I want. I ...

Converting a byte array to an image file using PHP

After receiving a JPEG byte array from Java SDK, I need to display that image using PHP. Is there a way to convert the byte array into a readable JPEG format for displaying it on a webpage? $byteArray = "[A@53d9e469"; //example of Java generated byte arr ...

retaining the scroll position of a window when refreshing a div

There's this issue that's been bothering me lately. I update the database via an ajax call, refresh the div, everything works fine, but it still scrolls to the top of the page. Here's what I have attempted: function postdislike(pid, user, ...

Icons from Material Design Lite are not appearing as expected when integrated into an Angular project

Recently, I integrated MDL into my Angular project. While most of it is functioning properly, the MDL icons seem to be giving me trouble... I've implemented them using <i class="material-icons">share</i>, but instead of displaying as an i ...

The previous and next buttons are displaying side by side rather than being positioned at the outer edges

I am having an issue where the prev and next buttons are displaying next to each other instead of at the edge of the div. Can someone please assist me in fixing this problem? Below is the provided HTML code: <div id ="moreOption_80322271" class="m ...

Button click triggering XMLHttpRequest not functioning properly due to null

I am facing an issue with my webpage. When I click on a certain section labeled as "trigger," it is supposed to print the content in the "#content" page. However, I want it to redirect back to the "home" section when I click on the "BACK" button that appea ...

Updating Angular model remotely without relying solely on the controller

I am struggling to call the addRectangleMethod method from my Javascript code in order to retrieve server-side information into the Angular datamodel. However, I keep encountering an error stating that the method I'm trying to call is undefined. It&ap ...

The measure of the leaflet map's vertical dimension in a Shiny module application

I'm facing an issue while trying to incorporate my small app as a module within my larger app. Everything seems to be working fine except for the height of the leaflet map. In the standalone app, I had: ui <- fluidPage( tags$style(type = "te ...

What is the method to link a progress bar to the value of a text input?

I'm currently working on an application where users need to input the percentage of their skill proficiency, and I want the progress bar to automatically reflect that value. I require assistance with this task, preferably using PHP only, but Java can ...

Encountering issues with the hyperlink tag '<a>' in an HTML document

I've encountered an issue with the code on my HTML page: <body> <div align="center"> <a href="../index.html"> <img border="0" src="banner1.jpg" width="800" height="120" alt="Ecommerce Knowledge Base"> &l ...

Symfony2 does not receive any feedback from the Ajax request

Perform an ajax POST request with no response: Here is the ajax request code snippet: $.ajax({ method: 'POST', url: "{{ path('app-like-add') }}", data: { imageId: id }, success: function(response) { ...

reduce the size of the image as the browser width decreases

Struggling with a webpage layout that features an image on the left and content area on the right, both with fixed widths. When reducing browser width, the image should not shrink but be cropped from the left side instead. Any solutions for this issue? ...

Generating symbols that combine both images and text seamlessly

I am working with a circle image that I need to resize based on its placement. This image is intended to be a background for a character or two of text. Specifically, whenever the number 1 or 2 appears in a certain element, I want the circle to appear beh ...

Laravel registration feature fails to properly update the users table in MySQL database

I am relatively new to using Laravel and encountering some challenges with the authorization process. I recently recreated an empty users table in my MySQL database by running the php artisan migrate:refresh command. However, after filling out the registra ...

The controller remains unresponsive when attempting to activate the button on the webpage

I'm a beginner in frontend development and I'm currently working on a website that uses Thymeleaf. On this website, there is a div block with a button. Please take a look at the HTML code below, specifically the button at the last three rows. &l ...