What is the best way to create a flexbox container that encompasses content with absolute positioning?

I am currently designing a website and I have envisioned a layout where there is a slideshow on the left side with corresponding text describing each slide on the right side. To achieve this, I am using flexbox for layout and absolute positioning for the images in the slideshow. However, I am facing an issue where the containing div does not fully wrap around the slideshow images, causing them to overflow the frame. Is there a way to make the div completely encapsulate the slideshow images while maintaining a maximum and minimum width set in the CSS?

Below is the current structure of my code:

HTML:

<div class="container">
    <div class="content">
        <div class="slides">
            <img src="http://placehold.it/2048x1365">
            <img src="http://placehold.it/2048x1365">
        </div>
    </div>
    <div class="content">
        <p>This is some content.</p>
        <p>This is some more content.</p>
        <p>This is some more content.</p>
        <p>This is some more content.</p>
    </div>
</div>

CSS:

.container {
    display: flex;
    justify-content: center;
    margin: 30px;
}
.content {
    background: red;
    flex: auto;
    flex-direction: column;
    min-width: 30em;
    max-width: 38em;
    padding: 10px;
    margin: 5px;
}
.slides {
    position: relative;
    width: 100%;
    height: 100%;
}
.content img {
    width: 100%;
    height: auto;
    position: absolute;
    display: block;
}

You can view the example on jsfiddle here.

Answer №1

The use of position: absolute for the image can disrupt the overall layout by removing it from the normal flow of elements, making it difficult to fully utilize flexbox as intended. Here are a couple of suggestions:

  • Show only one image programmatically
  • Display just the first image using CSS

I have implemented some modifications and put forth an alternative solution for the second option: http://jsfiddle.net/vuz9wzx5/2/

Update

If absolute positioning is necessary for the image, consider setting the height of the image container like demonstrated in this fiddle:

http://jsfiddle.net/vuz9wzx5/3/

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

On iPhones, the links display as oversized blank containers

Recently, a client who switched from an Android phone to an iPhone reached out to me with a complaint. She mentioned that the links on her website, which I built for her, appear as large empty boxes. You can view her website here. To illustrate the issue ...

Dynamic Website Layout Bootstrap 4 [ card designs and Tabs ]

Currently, I am in the process of developing a web application that needs to be responsive across various devices including mobiles, tablets, and PCs. My focus right now is on creating a user profile page that adapts well to different screen sizes. To achi ...

Efficiently determine optimal menu item dimensions using CSS automatically

Is it possible to automatically position menu items using CSS so that the position is recalculated when the menu item text changes? Currently, I have a menu created with ul li's and I am using padding for positioning. However, if the text becomes long ...

Is there a way to adjust the position of ::before elements without affecting the border placement?

I'm struggling with an element that has a CSS style ::before to display an arrow-up inside a black circle. Check out the code here The issue I'm facing is that the character \25b2 isn't centered vertically within the circle. Adjustin ...

What is the reason for the lack of letter-spacing between a nested inline element and the next character that follows?

Upon reviewing the specifications for letter-spacing, it is evident that runs of atomic inlines (e.g. inline-block) are considered as a single character (http://www.w3.org/TR/css3-text/#letter-spacing): For letter-spacing purposes, each consecutive run ...

Element flickering occurs when hovering over an element with an animation present

I'm currently working on a hover navigation, which was functioning properly until I introduced animations. Now, whenever there is an animation involving movement, it seems to flicker when hovered over. Here is the code causing the issue. When I remov ...

Ways to move the cursor to the search field after the placeholder text

I'm working on a Vue project with a small app featuring an input type search. The issue I'm facing is that the cursor appears at the beginning of the input, whereas I want it to appear after the placeholder text. How can I make this adjustment? ...

Incorporating CSS styling dynamically using Javascript

Just a heads up - I am completely new to coding and JavaScript, and this happens to be my very first post, so please bear with me. I have a set of Hex codes representing various colors, and my goal is to utilize JQuery to style some empty divs in the HTML ...

The top navigation menu is positioned above the sidebar menu due to a CSS error

Having an issue with adding top and side menus. The top menu is displaying above the side menu. Can someone help fix the css? Here is my fiddle. I attempted to apply #leftPanel position:fixed but it did not work as expected. ...

Controlling JS, CSS, and images with CakePHP 2.5 through the Cake controller

Currently, I am developing an application using the powerful combination of CakePHP and AngularJS. During my work on the AngularJS side of the project, I noticed that we are generating a large number of JavaScript and HTML files. I am interested in havin ...

"Navigate through the page by scrolling with your mouse all the way to 100

Is it possible to trigger an action when a user starts scrolling using the mousewheel? I've searched online but all I found was information on 100% scroll on click. I want the window to automatically be scrolled down to 100% as soon as the user starts ...

How is it possible that the sensitivity of the mobile slideshow is malfunctioning specifically when accessed through the Chrome browser in React?

My React web app features a carousel component that functions perfectly on Firefox. However, in Chrome on mobile devices, when I swipe down the page, it interprets it as a horizontal swipe and switches slides on the slideshow. The library I am using is cal ...

ngAnimate - Animation not activating on recurring custom directive

I am trying to implement ngAnimate on a custom directive that is repeated using ng-repeat in my AngularJS application. The animations function correctly when I use ng-repeat on a simple HTML list-item. However, when I replace the list-item with a custom di ...

Revamp the category style in Osclass

Although the Osclass is a useful tool, I have encountered some issues with it. Here is the code snippet: <div class="cell selector"> <?php osc_categories_select('sCategory', null, __('Select country/city', ...

Margins Disrupt Proper Text Alignment;

(If you know of a simpler solution to this issue, please share!) I am aiming for this website to consist of two text sections, one on each side of the screen. I managed to achieve this successfully by using text alignment and translate3d to shift the tex ...

Converting a 'div' element into a dropdown menu with CSS and Jquery

I am facing a challenge where I have a collection of buttons enclosed in a div that I want to resemble a dropdown: <div id = "group"> <label> Group: </ label> <div value =" 1hour "> 1h < / div> <div value =" 2hou ...

if the input field is empty, eliminate the class

Within the code snippet, a function is present which performs the following actions. It searches for an email in the input field, then converts the email to an md5 hash, and finally generates a Gravatar URL that is inserted into a class using fadeIn(); ...

No data appearing in the div elements

I have retrieved data from the database and I am attempting to display it inside a nested div structure. However, the data is not showing up in the intended div. Here is the problem I am trying to display the message You said: Hello 2hrs alongside the use ...

Superimpose a canvas onto a div element

I'm struggling to overlay a canvas on top of a div with the same dimensions, padding, and margins. Despite using position: absolute and z-index as suggested in similar questions, the canvas keeps appearing underneath the div. Here's my current co ...

Adjust the div to match the height of the td element

Hey there, can you help me out with this code snippet? <html> <body> <table> <tr> <td> <div class="the-div">h:100%</div> </td> ...