"Showcasing products on top of a background picture

I'm trying to achieve a specific layout on my codepen page, where the <div class="item__boxes"> element is displayed at the bottom of the <div class="item">. However, I've run into some issues and need help with the implementation.

Question:

How can I ensure that the <div class="item__boxes"> element stays at the bottom of the <div class="item"> regardless of the content inside?

Goals:

  1. Make sure there is always padding/margin between the text in <div class="item__text"> and the <div class="item__boxes">.
  2. Ensure that the <div class="item__boxes"> is consistently positioned at the bottom of the <div class="item"> across different screen sizes.

Current Issue:

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

Desired Output:

https://i.sstatic.net/gfQlX.jpg

Code:

.item {
  position: relative;
}
.item__wrapper {
  max-width: 50%;
  position: relative;
}
.item__img img {
  width: 100% !important;
}
.item__text {
  position: absolute;
  background: rgba(238, 238, 238, 0.5);
  padding: 64px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.item__boxes {
  background-color: #ccc;
  display: flex;
  position: absolute;
  bottom: 0;
}

.col-padding {
  padding: 16px;
}
.col-m-12 {
  width: 100%;
}

@media (min-width: 1024px) {
  .col-t-6 {
    width: 50%;
  }
}
<div class="item__wrapper">
<div class="item">
<div class="item__img">
<picture>
<source media="(min-width: 1300px)" srcset="https://placeimg.com/1000/480/nature">
<source media="(min-width: 1024px)" srcset="https://placeimg.com/960/480/nature">
<img src="https://placeimg.com/640/480/nature" alt="Flowers" style="width:auto;">
</picture>
</div>
<div class="item__text">
<h3>Some title</h3>
<p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
</div>
</div>
<div class="item__boxes">
<div class="col-m-12 col-t-6 col-padding">
<div>Some Title</div>
<div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Globally Title</div>
<div>Globally impact integrated infomediaries via seamless mindshare. </div>
</div>
<div class="col-m-12 col-t-6 col-padding">
<div>Distinctively Title</div>
<div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
</div>
</div>
</div>

Answer №1

I experimented with your code and found a solution to ensure consistent padding regardless of screen width. To achieve this, I suggest using relative positioning for the text and absolute positioning for the image. Instead of setting padding-bottom based on width, consider including the image as a background-image in CSS and set its size to cover. This approach eliminates gaps no matter the screen dimensions.

I tested the code provided at 80% width with padding set to 33% (excluding the background image code). At the original 50% width, no additional bottom padding was needed.

The snippet code may not run due to the CSS structure, but I'm sharing it for future reference. Here are links to view the code on Codepen: first link and second link.

Hopefully, this information proves helpful.

.item {
  position: relative;
  &__wrapper {
    max-width: 50%;
    position: relative;
    min-height: 100vh;
  }
  &__img {
    img {
      top: 0px;
      position: absolute;
      width: 100%!important;
    }
  }
  &__text {
    top: 0px;
    position: relative;
    min-height: 100vh;
    background: rgba(238, 238, 238, 0.5);
    padding-right: 50px;
    padding-left: 50px;
    padding-top: 30px;
    //padding-bottom:33vh at 80%;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: top;
    justify-content: center;
  }
  &__boxes {
    background-color: #ccc;
    display: flex;
    position: relative;
    bottom: 0px;
  }
}

.col {
  &-padding {
    padding: 16px 16px 5px 16px;
  }
  &-m-12 {
    width: 100%;
  }
}

@media (min-width: 1024px) {
  .col {
    &-t-6 {
      width: 50%;
    }
  }
}
<div class="item__wrapper">
  <div class="item">
    <div class="item__img">
      <picture>
        <source media="(min-width: 1300px)" srcset="https://placeimg.com/1000/480/nature">
        <source media="(min-width: 1024px)" srcset="https://placeimg.com/960/480/nature">
        <img src="https://placeimg.com/640/480/nature" alt="Flowers" style="width:auto;">
      </picture>
    </div>
    <div class="item__text">
      <h3>Some title</h3>
      <p>Efficiently communicate sticky quality vectors after compelling growth strategies. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally
        procrastinate. Compellingly scale future-proof content rather than enterprise users. Uniquely build scalable applications vis-a-vis performance based functionalities. Monotonectally procrastinate.</p>
    </div>
  </div>
  <div class="item__boxes">
    <div class="col-m-12 col-t-6 col-padding">
      <div>Some Title</div>
      <div>Enthusiastically incubate diverse initiatives without multifunctional strategic theme areas.</div>
    </div>
    <div class="col-m-12 col-t-6 col-padding">
      <div>Globally Title</div>
      <div>Globally impact integrated infomediaries via seamless mindshare.< /div>
    </div>
    <div class="col-m-12 col-t-6 col-padding">
      <div>Distinctively Title</div>
      <div>Distinctively strategize long-term high-impact ideas whereas client-centered leadership skills.</div>
    </div>
  </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

Chrome clip-path creates a white horizontal line shape that resembles a paperclip

Having an issue with horizontal white lines appearing through a div with clip-path set and background image in Chrome. Any suggestions on how to fix this? Check out the screenshot for reference: Screenshot showing the horizontal white line bug If you nee ...

Identifier for md-radio-group

In my Angular 4 Material application, I have a set of radio buttons grouped together: <md-radio-group fxLayout fxLayoutAlign="center center" fxLayoutGap="30px"> <md-radio-button value="1">Date</md-radio-button> <md-radio-butto ...

Which JSF element is capable of displaying a <div> element?

For example, h:inputText will display an "input type='text'". Which JSF tag is used to render a "div" element? ...

How to align content within a FormControlLabel using Material UI

My goal is to line up the label and radio button inside a FormControlLabel component so that the label occupies the same width regardless of its content. The current appearance can be seen below: https://i.stack.imgur.com/GhXed.png Below is the code I am ...

Deactivate a chosen item following selection

Is there a way to deactivate a selectable element after it has been clicked in the scenario below? Additionally, I would like to modify its CSS style. $(function(){ $("#selectable").selectable({ stop: function() { var result = $( "#select-re ...

What is the process for adding an SVG image (icon) to the navigation bar of a Quarto document?

I am trying to incorporate an SVG icon into the navigation bar using Quarto, but I am facing difficulties in getting it to work. The code snippet from my _quarto.yml file looks like this: navbar: ... right: - icon: github href: https://github.com/ ...

How can we evenly distribute buttons in Bootstrap 4 while also ensuring they are vertically aligned?

When attempting to generate buttons using the code below, I encountered issues with the buttons not spreading across the container as expected after using the btn-block class. Additionally, the buttons did not center-align, despite using the justify-conten ...

What's the reason behind CSS transitions starting with a black background?

When I apply a transition to the heart, it inexplicably turns black at the start of the animation before displaying the intended gradient effect. Below is the code snippet: .heart { font-size: 2.5rem; padding-right: 2rem; } .heart:hover ...

Troubleshooting problem with Angular 2 in Internet Explorer related to the use of [style]="

I've encountered a challenge while using angular 2 (2.0.0-beta.17). The app works perfectly on most browsers, but as expected, IE 11 is causing trouble. The scripts included in the head for angular are: <script type='text/javascript' sr ...

Tips for Utilizing Border-Radius in Safari

What is the best way to hide a child element's corners within its parent (#div1) Ensuring that the child does not overflow its parent container? ...

Tips for placing a searchbox on top of a carousel?

I need to create a search box that overlays on top of a carousel image. I currently have the search box positioned absolutely, but it's not responsive as it doesn't stay within the carousel as the width decreases. How can I make it responsive whi ...

Transforming Codeigniter Forms into Custom HTML

I need help converting the following CodeIgniter code into HTML. Can someone assist me with this? <?php echo form_open('contact/create_member'); echo form_input('name', set_value('name', ' Name')); echo form_in ...

Tips for maintaining the original ng-click initialized value as the ng-init value after the page is refreshed

My ng-repeat feature includes buttons for liking and disliking images. The problem I'm facing is that each time the page refreshes, the count of likes and dislikes gets reset to the initial value set by ng-init. How can I maintain the incremented lik ...

Tips on adjusting the size of a Materialize CSS datepicker to perfectly fit within a card

Currently, I am developing a login page in html utilizing the materialize css framework. In my design, I created a card where Login and Register are displayed as tabs within the card. However, one of the forms includes a datepicker from materialize which ...

Original code

I have a database containing HTML code for a table. I would like to display this code in its original form within a textarea so that I can edit it. However, when I try to echo the code, it appears in compiled form as a table rather than the original HTML ...

What is the best method to enable horizontal scrolling within a div element by overflowing its content?

My layout looks like this: <div id='container'> <div id='cont1' style='width:150px'>Content 1</div> <div id='cont2' style='width:150px'>Content 2</div> <div id=' ...

Add a pair of assorted div elements to a shared container

I have two different sections with classes named "red" and "blue". By default, these sections are hidden. I want to duplicate them and display them in a single container named "cont". The red button appends the red section and the blue button appends the b ...

Basic CSS3 animation

I seem to be having trouble making the transition effect work in this piece of code I want to change the text alignment from left to right, but it's not working. The code is very simple. <style> /* Default State */ div { background: green; ...

Guide on combining vendor CSS files in a React application using Webpack

Incorporating third-party libraries is an essential part of my project. For example, I have Mapbox GL installed via npm, which comes with CSS files needed for its functionality. The Mapbox GL CSS file can be found at mapbox-gl/dist/mapbox-gl.css in the no ...

How to Enhance Angular ui-router nested views with Resolve?

I have been working on creating a customized version of my Angular 1.4.12 application with nested views. The main purpose behind this customization is to accommodate sections within the app that require a header/content/footer structure, while others do no ...