I am attempting to dynamically align the images of two articles. The exact heights of the containers are not specified. Can anyone provide guidance on how to achieve this?

My code snippets:

<article class="featured">
    <img src="http://www.placehold.it/300x100/ff0000">
    <p>
        <!--Text-->
    </p>
</article>
<article class="sub-featured">
    <img src="http://www.placehold.it/300x100/00ff00">
    <p>
        <!--Text-->
    </p>
</article>
<article class="sub-featured">
    <img src="http://www.placehold.it/300x100/0000ff">
    <p>
        <!--Text-->
    </p>
</article>

Also, my SASS code:

body{
 margin:0;
 img{width:100%;}
 article.featured{
    p{width:50%;}
 }
 article.sub-featured{
    width:50%;
    margin-left:auto;
 }
}

This is the current state of my HTML:

https://i.sstatic.net/2IET4.png

I aim for it to resemble this design:

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

The challenge here is achieving this design responsiveness across different screen sizes. The alignment I seek is having the bottom of the green image consistently align with the bottom of the red image regardless of the screen width. Applying position:relative or using CSS transformations won't suffice due to the unpredictable height of the articles.

Any assistance would be greatly appreciated!

Answer №1

Is this the desired format?

.redImage {
  position: relative;
}

.redImage img {
  width: 100%;
  height: auto;
}

article {
  width: 50%;
  z-index: 1;
  float: left;
  box-sizing: border-box;
  padding: 20px;
  overflow: visible;
  position: relative;
}

.specialImage {
  position: absolute;
  bottom: 100%;
  z-index: 1;
}

.specialImage img {
  width: 100%;
  height: auto;
}

body {
  margin: 0;
}
<div class="redImage">
  <img src="http://dummyimage.com/1200x3:1/f00/fff" />
</div>
<article>
  <h3>Introduction</h3>
  <p>The Alaskan Rolling Rock plans an escape from a sudsy IPA a flirty Dixie Beer. A grizzly beer greedily can be kind to a paternal Long Trail Ale. A sake bomb around a bud light, a PBR, and the frozen Budweiser are what made America great! A crazy pool
    table caricatures the mug. When a Sam Adams for a Dixie Beer self-flagellates, a Bacardi Silver returns home.</p>
</article>
<article>
  <div class="specialImage">
    <img src="http://dummyimage.com/1200x3:1/ccc/f00" />
  </div>
  <h3>A polar bear beer</h3>
  <p>When some Dixie Beer takes a coffee break, the optimal shot beams with joy. Any PBR can derive perverse satisfaction from an Octoberfest, but it takes a real Miller to wastedly recognize a scooby snack near the coors light. A milwakees best for a miller
    light ignores a chain saw. A psychotic Hazed and Infused buries a bill. An Ipswich Ale about a Stella Artois gives lectures on morality to a coors light of a scooby snack.
    <h3>The fried Red Stripe</h3>
    <p>Any Heineken can dumbly graduate from the porter living with the Rolling Rock, but it takes a real keg to knowingly bury a tooled Lone Star. A scooby snack negotiates a prenuptial agreement with a bar tab. An Amarillo Pale Ale beams with joy, because
      a Long Trail Ale of a Sam Adams requires assistance from another frozen bar tab. When a miller light near a PBR ceases to exist, the Imperial Stout about a booze ruminates. A beer gives the last beer to the power drill drink.</p>
</article>

If not, please provide further clarification.

Modify the dummyimgs ratios and observe that it consistently works (even when the small image's height exceeds the big image's height - the small image will have the head cropped in this unique scenario).

jsFiddle

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

Attempting to locate the element's position using Selenium in Python

quem_esta_sacando = driver.find_elements_by_xpath("//div[@class='gameinfo-container tennis-container']/div[@class='team-names']/div[@class='team-name']") this is how I located the correct class, but now I want to ...

Embedding a video element results in an unexpected increase in height

When I insert an HTML5-Video element into a div, it results in the wrapper having a height larger than the video itself. The wrapper is 7px taller than the actual video source, without any min-height set. Check it out! (Scroll down to the Video) The vide ...

Assorted dimensions of square grid

Is it feasible to achieve the following using only HTML and CSS? The condition is that since the divs are automatically generated in a list, they should not be nested within another HTML element (such as adding a div for each line is restricted): Here is ...

Cascading Style Sheets can be disrupted by Scalable Vector Graphics

Currently, I am incorporating SVG Icons that I created in Illustrator into my Vue.js Webapp. I have utilized Webpack's "require" to load the icons. Rather than accessing the SVGs directly using the src attribute of the img tag, I am inserting them usi ...

Developing a unified input element containing numerous fields

After @grateful answered this question, I wanted to elaborate in case it could benefit others... In my project, there's a page called rsetup.php which has some PHP code to access a MySQL database for filling the HTML content of the page. This HTML ge ...

Instructions on utilizing the CSSStyleSheet.insertRule() method for modifying a :root attribute

Is it possible to dynamically set the background color of the :root CSS property in an HTML file based on a hash present in the URL? The code provided does change the background color, but unfortunately, the hash value doesn't persist as users navigat ...

Ways to center text horizontally in a line with the help of bootstrap styles?

.list-group-item{ width: 165px; height: 32px; line-height: 1px; text-align: center; margin-bottom: 1px; margin-top: 58px; margin-left: 20px; } <ul class="list-group" v-if="showSearchHistory"> <li class="list-g ...

Spacing in CSS between the menu and its submenu elements

My current challenge involves creating space between the menu and the submenu. However, I've noticed that when there is this space, the submenu doesn't function correctly. It only works when the design has no gap between the menu and the submenu. ...

Switching the horizontal tab design from Bootstrap 3 to Bootstrap 4

I'm currently working on adapting a code snippet from bootsnip that creates horizontal Bootstrap tabs with material-style design. I've encountered some challenges in converting it to Bootstrap 4, specifically in updating the CSS to use .nav-item ...

Use the angular cli to incorporate the CSS styles found in the node_modules directory

After successfully installing a new library with npm, I now face the challenge of importing the CSS into my project. It seems unwise to directly link to the node_modules folder. Can anyone suggest an easy way to import this CSS into my Angular CLI project? ...

Using jQuery, you can easily modify the color of a TD cell by applying the css properties assigned to the div element

I am attempting to implement a jQuery script that will execute upon the loading of the document. The objective is for the script to retrieve the background color of a div located within a td cell and apply it as the background color for the respective td c ...

Problem with animated scrolling in Jquery

Currently, I am working on a function that aims to smoothly scroll the web to a specific div each time a user scrolls "into" a container div. You can get a better idea of what I mean by looking at my JSFiddle. Everything works perfectly when the user scro ...

Image swaps with timer for button

I am working on a project where I have a page with 5 image buttons arranged horizontally. The objective is to have the images on each button change sequentially every 3 seconds in a continuous loop. Here is my code: $(document).ready(function (){ Beg ...

Do colors appear differently on various screens?

I've noticed that the background color #1ABC9B appears differently on various monitors when viewing my website. On MAC systems and smart phones, it appears as a lighter shade of green compared to other laptops where it appears darker. What could be ca ...

Steps for eliminating a column from a table

By including the detailPanel option, a new column with an icon button will be automatically added. Is there a way to eliminate this additional column that is generated? Appreciate your help! ...

Contrasting box-shadow behavior observed in Chrome versus Firefox

I'm working on a project and aiming to achieve this design: https://i.stack.imgur.com/YflaU.png To test it out, I created a sample page with the following code: p { display: inline; background-color: yellow; box-shadow: 10px 0px 0px red, -1 ...

css failing to load properly following javascript redirection

Upon clicking the button labeled id=cancel, the user will be directed to index.php. $('#cancel').click(function() { if(changes > 0){ $('#dialog-confirm').dialog('open'); }else{ window.location.href = ". ...

Issue with aligning the image product in Bootstrap 4

I'm currently working on creating a basic online shopping page for my PHP training, and I've run into a bit of a roadblock with the HTML portion. Even after using Bootstrap, I'm still struggling to simplify things. When I view the result of ...

Switching to a dropdown navigation option

Sorry for the repetition, but I haven't been able to find a solution to my problem yet, so here I am asking again. I am still getting the hang of html5 and css3, and while I've managed so far, I'm stuck now. I want to turn one of the option ...

Click and Rotate for More Information

Hello everyone, I have a question regarding creating a unique Tumblr theme. My goal is to make the posts rotate on the y-axis when clicked, revealing like and reblog information. Currently, I've been able to achieve this effect on hover by using code ...