Display the position information box next to the automatically adjusted gallery

There are two demos hosted on an external site:

The page without text displays the expected behavior with proper autosizing. My initial query is: Why does the info div not shrink to the width of the wrapper in the second and third pictures?

And the primary question: How can I position the info box at the right side of the images, so that the wrapper adjusts its size properly to accommodate the combined width of the image and text while remaining centered in the viewport?

I attempted using floating but it did not work with unsized elements.

Thank you in advance.


This is my current setup:

// jQuery (to be improved later):

$(document).ready(init);

function init() {
  $(".active").on("load", function(evt) {
    setActive($(this).parent(), $(this));
  });

  $(".images").on("click", "img", function() {
    showNextImage($(this).parent());
  });
}

function showNextImage(parent) {
  if(parent.find(".active").next("img").length != 0)
    setActive(parent, parent.find(".active").next("img"));
  else
    setActive(parent, parent.find("img:first"));
}

function setActive(parent, element) {
  parent.find(".active").removeClass("active").css("z-index", 0);
  element.addClass("active");
  element.css("z-index", 10);

  autoSizeParent(parent, element);
}

function autoSizeParent(parent, element) {
  parent.width(element.width());
  parent.height(element.height());
}
.wrapper {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1em;
  background: white;
}

.images {
  position: relative;
  overflow: hidden;
}

img {
  position: absolute;
  max-height: 540px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="wrapper">
  <div class="images">
    <img class="active" src="http://i.imgur.com/94WEXSB.gif" />            
    <img src="http://i.imgur.com/C0JSZMJ.gif" />           
    <img src="http://i.imgur.com/bfDOcv1.gif" />           
  </div>
  <div class="info">
    <h2>Title</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquam incidunt perferendis, porro natus obcaecati ut! Voluptate perferendis, dicta, perspiciatis blanditiis eligendi ab optio, culpa totam laboriosam veniam ipsam repellendus, ullam.</p>
  </div>
</div>

Answer №1

Now I can't get enough of using display: flex

.container {
    position: fixed;
    display: flex;

    top: 50%;
    left: 50%;

    transform: translate(-50%, -50%);

    padding: 1em;
    background: white;
}

.gallery {
    position: relative;
    overflow: hidden;
}

.information {
    width: 462px;
    margin-left: 30px;
}

img {
    position: absolute;
    max-height: 540px;
}

To arrange the information below the images, use flex-direction: column on the container. Information width is dynamically set using JavaScript.

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

Instructions for including a scroll bar in an HTML side menu

Can anyone help me figure out how to add a scroll bar specifically for the left side navigation menu? I've tried adding overflow-y: scroll; in different places, but it hasn't worked so far. I'm still learning web design and have been piecing ...

Error: The method 'editable' is not defined for the jQuery.jEditable object [object Object]

It seems like there is an error with this jeditable object. This is my webpage <script src="/assets/jquery.js?body=1" type="text/javascript"></script> <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> .. ...

"Refreshing the layout in Asp.Net MVC only involves re-rendering the RenderBody() content when navigating

Is there a way to reload just the views in the RenderBody() section of my layout without refreshing the entire page when clicking on the navigation menu? What is the most effective method to achieve this? ...

Pop-up with a unique MediaBox design

Last week, I inquired about window pop-ups and have been brainstorming alternatives. One idea I had is to use mediabox/lightbox style pop-ups. Would it be feasible to create a link that opens a mediabox window off to the side when clicked? Users could dra ...

How can I turn off a CSS transition for a particular line of code?

Hey there! I'm dealing with a div that has a fixed height, but when hovered over, it expands by a specific amount. I've also managed to make the background color change upon hovering over the div. The issue arises when both the height and backg ...

Tips for fixing CORS error when working with the fetch API

I'm having trouble retrieving data from the metaweather.com API using JavaScript's fetch function. I attempted to include before the API URL, but it has not resolved the issue. I followed a video tutorial on how to fetch data, but I'm stil ...

What is the preferred method for writing `*zoom: 1;` in CSS?

Trying to create my code, I decided to borrow some CSS files from older code. However, upon running yarn build I encountered several errors like: ▲ [WARNING] Expected identifier but found "*" [css-syntax-error] <stdin>:122:2: 122 │ * ...

What is the best way to modify the colors of two specific elements using a combination of CSS and JavaScript

I am currently developing a browser-based game and have encountered an issue. Here is the relevant line of my HTML/PHP code: echo '<div id="div'.$n.'" class="d'.$rand.'" onclick="swapit(this.id, this.className)"></di ...

What causes the smart app banners to be hidden in Safari even with a specified viewport?

Is there a way to ensure that a smart app banner always displays completely on a webpage when linking to an app in the Apple App Store? I have encountered issues where the banner is hidden either behind the address bar or partially obscured depending on th ...

CSS text wrapping will now occur on underscores as well as spaces and hyphens

I am facing an issue with long file names in my HTML formatting causing overflow. These file names use underscores instead of spaces, making it difficult to wrap them properly. For example: Here_is_an_example_of_a_really_long_filename_that_uses_underscore ...

What is the best way to integrate inline radio controls in React-Bootstrap?

Currently, I am working on my personal project using Electron, React-Bootstrap, and Typescript. However, I am facing an issue with placing two radio controls next to each other. Despite following the examples from React-Bootstrap, I have not been success ...

I am seeking a way for my menu to dynamically change depending on the specific view in React, without using reactdom.render

After noticing that my app only shows the menu bar when I have dev tools open, I realized I might be doing something wrong. On my landing page, there is a menu bar with the app's logo, menu items, and a log-in button in my web app. Here's an exa ...

Obtaining the responseJSON property from a jQuery $.ajax object involves accessing the data returned

Recently, I encountered an issue with my JavaScript code that involves an AJAX request: $ajax = $.ajax({ type: 'GET', url: 'DBConnect.php', data: '', dataType: 'json', success: function(data) {} ...

An iframe for the Vimeo player set to 100% of

I encountered some challenges while styling the Vimeo video I embedded. Here is the player I am using: I want the player to occupy the entire screen for all viewport sizes, so I applied min-width: 100vh and min-height: 100vw. I was able to adjust the wi ...

Two tables are positioned using distinct alignments but share a common stylesheet

I have created two tables, one using HTML (with a touch of PHP) and the other with two PHP loops. Starting with the stylesheet: .statistics { font-family: Arial, monospace; font-size: 36px; margin-left: 5%; width: 90%; } .statistics tr { ...

When the border width is set to 1px in FireFox, the border size is calculated as 0.667

When using the FireFox browser alone, I noticed that the border size is displayed as 0.6667 when setting the border width to 1px on a div, input element, or any HTML element. The same issue occurs whether the border is applied using inline CSS or a separat ...

The setTimeout function executes immediately without any delay

In my code, an html button triggers a jQuery function (let's call it funcOne) which then calls another function (funcTwo) recursively to modify CSS in the DOM. The funcTwo function involves setTimeout() calls to create a blinking effect by delaying th ...

Divergent behavior of jQuery AJAX when used with a standard form versus when called in a popup within a div

Why does the jQuery AJAX work perfectly when submitting a form using the normal method, but not when submitting the same form within a popup? Below is the code for reference. Form submission script: $("#submit").click(function (e) { /* $('form&a ...

Issue with Jquery - Variable not getting updated on resize event, causing multiple saves

After creating this jQuery script to enable/disable a fixed position div based on user scrolling behavior, I encountered an issue where the functionality breaks upon window resizing. Despite my attempts to update the variables correctly after resizing, the ...

Error encountered in Webpack 4 when trying to compile node modules CSS file: Unexpected .(dot) token

I am currently in the process of transitioning my React project from client-side rendering to server-side rendering. Unfortunately, I have encountered an issue with my webpack configuration for CSS that was working perfectly fine in my original project (c ...