Position the image to float at the bottom of the enclosed element

I have a container with an image that is floated to the right side:

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

<body style="
    width: 300px;
">
    <img style="
    background: red;
    width: 100px;
    height: 150px;
    float: right;
    /* position: relative; */
    /* top: 112px; */
"><h1 style="
    margin: 0;
">Lorem ipsum dolor sit amet
</h1>


    <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</div>

</body>


I want to move the image to the end of the container while still having the text wrap around it:

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

Is there a way to achieve this without breaking the text wrapping around the image? I've checked similar questions but they seem more focused on using floats for design rather than addressing this specific issue.

Answer №1

Utilize the CSS properties display: table and table-cell, then adjust the vertical alignment to bottom.

.img {
  background: red;
  width: 100px;
  height: 150px;
  float: right;
}
<body style="width: 300px;">
  <div style="display: table">

    <div style="display: table-cell">

<h1>Lorem ipsum dolor sit amet</h1>

      <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</div>

    </div>

    <div style="display: table-cell; vertical-align: bottom;">
    
      <img class="img" />
    </div>

  </div>

</body>

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

Technique in CSS/SASS to repair a div

Seeking a solution for fixing divs with text in CSS. I am aware of the background-attachment: fixed; property which creates a fancy effect. Is there a similar property to "fix" divs with text or how can this be achieved in Typescript? Your insight would be ...

Implementing PHP function upon clicking an HTML button

Hey there! I'm trying to trigger the bb() function when a button is clicked. Unfortunately, the code below isn't working as expected. Can you help me out? echo "<div class ='i2' id=".$x.">"; echo "<button type='button&ap ...

Is there a way to customize the email content for Opencart orders according to our preferences? Can we make changes to it

Is it possible for me to modify the content of the order email? Which specific file should I refer to for this? This is a confirmation of an online transaction made with ######. The AuthOnly transaction amounted to $171.90 and will soon be processed to y ...

The Angular service encounters issues when interacting with REST API

Within my application, a template is utilized: <div class="skills-filter-input" ng-class="{'hidden-xs': skillsFilterHidden}"> <input type="text" ng-model="skillQuery" ng-change="filterSkills()" placeholder="Filter skills" class="filter- ...

Setting up a static directory in Node Express to serve index.html along with additional tsv files

I'm encountering an issue with setting up a static folder for a project using the d3 node package. My approach involves using express to host a server.js file, which is structured as follows: var express = require("express"); var app = express(); var ...

Adjusting the height of table rows in Angular within a Razor cshtml file

Is there a way to set the height of a table row and ensure it respects the defined height without taking different heights? I tried using styles with white-space: pre-wrap, overflow: hidden, and text-overflow: ellipsis, but it's not working as expecte ...

Creating consistently sized rows of Bootstrap columns - with either equal heights or equal spacing between each row

It would be great if bootstrap had a built-in feature where it automatically assigns the wrapper div of any item with a height based on the height of the largest div. In this example on JSFiddle, you can see that I have different heights for the video-ite ...

The evolution of web development: HTML5's History API meets

Currently, I am in the process of developing an MVC application that features a customized tab interface on the webpage. When a user selects a specific tab, an AJAX GET request is triggered to load fresh content into the body area of the tab. Everything is ...

Creating an Interactive Countdown Timer with JavaScript

I am currently working on a website that includes a modified version of a JavaScript countdown element. While I have been learning a lot about flex grids, I haven't delved much into block/inline-block layouts. One issue I'm facing is that when t ...

Simplifying the process of importing SCSS files in Angular 5

After extensive searching, I've come up empty-handed in finding a solution to my project dilemma. Let's say I have various .scss files within my project such as mixins.scss, vars.scss, and base.scss. Naturally, I would like to use these files in ...

Alter the color of textbox text using JavaScript

I have a text input field. When clicked, I want to change the text color style using JavaScript. Previously, I successfully achieved clearing the inner content of the textbox when clicked and reverting to the default version on blur. This code is currently ...

Divs gracefully appear one after the other in a sequential manner

I am attempting to showcase a sequence of 4 divs in a row using the ease-in CSS transition feature. I came across this example that demonstrates what I am aiming for: http://jsfiddle.net/57uGQ/enter code here. However, despite my best efforts, I am unable ...

Utilize a personalized container for the slider's thumb within a React application

Is it possible to replace the slider thumb with a custom container/div in React instead of just styling the thumb or using a background image? I have found a codepen example that demonstrates what I am trying to achieve, but unfortunately I am having trou ...

Can an HTML page be created where certain elements cannot be targeted using CSS selectors or XPaths?

To put it differently: Do any HTML structures restrict the selection of elements using CSS selectors? Do any HTML structures restrict the selection of elements using XPaths? Appreciate it! :) ...

The outcome in my EJS file is not as expected when employing a for loop

I am currently developing a task management app, following along with my instructor's guidance. While my instructor's code is functioning properly, I am encountering an issue with my for loop. The only difference seems to be the variable names us ...

Integrating dual Google Maps onto a single HTML page

I'm facing an issue with implementing two Google maps on a single page where the second map seems to be malfunctioning. Below is the code I am currently using: <style> #map-london { width: 500px; height: 400px; } #map-belgium { wi ...

Creating a torn paper illusion using CSS masking techniques

My goal is to create a ripped/lined paper effect using CSS mask. It's working well and looks good. However, I'm struggling to apply the mask at the top as well. Here's what I've tried so far: mask-image: linear-gradient(white, white), u ...

Generate a custom map by utilizing JavaScript and HTML with data sourced from a database

Looking for guidance on creating a process map similar to this one using javascript, html, or java with data from a database. Any tips or suggestions would be appreciated. https://i.sstatic.net/tYbjJ.jpg Thank you in advance. ...

The image is not appearing on mobile devices, but it is displaying correctly on desktop computers

Having trouble with my landing page on compare.comxa.com. When I try to view it on my Android device, only the form shows up and the background image is nowhere to be found. Can anyone help me troubleshoot this issue? Here is the code: ...

Understanding the scope of variables in JavaScript when using an anonymous function with addEventListener

Upon clicking on each div, an alert will display '1' if div 1 was clicked, or '5' if div 2 was clicked. This code has been simplified for ease of use in a larger application. <html> <head> <style type="text/css"> #div ...