Place two divs in the middle of another div with equal spacing in between

I am having trouble aligning two divs horizontally within another div while setting a maximum width for each. Additionally, I would like some spacing between the divs to avoid them touching.

The following code isn't yielding the desired outcome:

HTML:

<div class="container" id="outer">
  <div id="inner">
    <h2>Heading!</h2>
    <p>Text</p>
    <p>More text</p>
  </div>
  <div class="frame">
    <p>Description</p>
    <img src="path to image" />
  </div>
</div>

CSS:

.container {
  min-height: 400px;
  padding: 3vh 1vw;
}

#outer {
  overflow: hidden;
  text-align: center;
  margin: auto;
  display: inline-block;
}

#inner {
  width: 50%;
  max-width: 600px;
  text-align: justify;
  height: 422px;
}

.frame {
  position: relative;
}

.frame img {
  border: 10px solid #fff;
  border-bottom: 45px solid #fff;
  -webkit-box-shadow: 3px 3px 3px black;
  -moz-box-shadow: 3px 3px 3px black;
  box-shadow: 3px 3px 3px black;
  width: 50vw;
  max-width: 450px;
}

.frame p {
  position: absolute;
  text-align: center;
  width: 100%;
  bottom: 0px;
}

Answer №2

adjust the width of an inner div and apply a margin as needed

.item {
  min-height: 400px;
  padding: 3vh 1vw;
  background-color:#f00;
}

#outer-container {
  overflow: hidden;
  text-align: center;
  margin: auto;
  display: inline-block;
}

#inner-div {
  width: 50%;
  max-width: 600px;
  text-align: justify;
  float: left; 
  height: 422px;
  background-color:#0f0;
  margin-right:10px;
}

.photo-frame {
  position: relative;
  width: 45%;
  max-width: 350px; 
   float:left; 
}

.photo-frame img {
  border: 10px solid #fff;
  border-bottom: 45px solid #fff;
  -webkit-box-shadow: 3px 3px 3px black;
  -moz-box-shadow: 3px 3px 3px black;
  box-shadow: 3px 3px 3px black;
  width: 50vw;
  max-width: 450px;
}

.photo-frame p {
  position: absolute;
  text-align: center;
  width: 100%;
  bottom: 0px;
  bottom: 0px;
}

Answer №3

Do you think this solution would meet your needs? Check it out here

.thing {
  min-height: 400px;
  padding: 3vh 1vw;
}

#outer {
  overflow: hidden;
  text-align: center;
  margin: auto;
  display: inline-block;
  width: 100%;
}

#inner {
  width: 50%;
  max-width: 600px;
  text-align: justify;
  /* float: left; */
  height: 422px;
  display: inline-block;
}

.polaroid {
  position: relative;
  /* width: 50%;
  max-width: 350px; */
  /* float:left; */
  display:inline-block;
  width: 200px;
  vertical-align: top;
}

.polaroid img {
  border: 10px solid #fff;
  border-bottom: 45px solid #fff;
  -webkit-box-shadow: 3px 3px 3px black;
  -moz-box-shadow: 3px 3px 3px black;
  box-shadow: 3px 3px 3px black;
  width: 50vw;
  max-width: 450px;
}

.polaroid p {
  position: absolute;
  text-align: center;
  width: 100%;
  bottom: 0px;
  bottom: 0px;
}
<div class="thing" id="outer">
  <div id="inner">
    <h2>Heading!</h2>
    <p>Words</p>
    <p>More words</p>
  </div>
  <div class="polaroid">
    <p>Words</p>
    <img src="path to image" />
  </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

Ways to automatically adjust the margins of my HTML body page

I'm currently working on a school project to develop a website. The challenge I'm facing is customizing the navbar and header background colors in such a way that they extend seamlessly to the end of the page. Despite my efforts, there seems to b ...

Limitations on Embedding Videos with YouTube Data API

I have been using the Youtube Data API to search for videos, but I am encountering an issue with restricted content appearing in the results. Specifically, music videos from Vevo are showing up even though I only want videos that can be embedded or placed ...

Is it possible to scroll only a portion of a div element without relying on absolute positioning and when the

HTML: <div class="block"> <div class="header">Some text</div> <div class="content"> <p> Unique content goes here. </p> <p> More unique content for demonstration ...

A convenient method for converting horizontal columns into vertical columns on mobile screens without using <div> tags or setting a minimum width, perfect for email formatting

After experimenting with using <div> elements and applying a min-width attribute to an email, I have come to the conclusion that these methods do not yield satisfactory results. While the alignment of horizontal columns works well on desktop screens, ...

Issue with Responsive Behavior of Multi-Row Cards in Bootstrap 4

My goal is to create responsive rows of cards with some margin, but I am running into issues. When I use margin:5px; on my cards, the row overflows and they are not centered correctly. There seems to be extra space on the right side of the cards. How can I ...

The alignment of Flex Divs is off despite having identical heights

I'm facing an issue where divs are not staying at the top of their parent div if the image they contain does not have the same height as the others. Within my navbar, I have icons of varying sizes placed inside divs using display: flex to vertically ...

Can the font size of a container be adjusted proportionally to its width or height using only CSS?

When it comes to ensuring that the font always fits nicely within its container, I rely on using Javascript to set divs or specific class to have their font-size dynamically equal to their width, and adjust their inner text elements accordingly. If you wa ...

Looking for assistance with aligning an image in a <td> cell that doubles as a link?

How can I center a play icon in the middle of a td cell and make the entire content clickable as a link, including the background image? I've tried various methods but can't seem to get it right without breaking the alignment. Any suggestions wou ...

Tips for choosing Week Range values with Selenium WebDriver

Currently, I am working with Selenium WebDriver and I am trying to figure out how to select week range values from a dropdown menu at once. I have a dropdown called Period, which, when selected, automatically reveals additional dropdowns for From week and ...

What are some ways to display multiple divs within a single popup window?

I am attempting to create the following layout: Here is what I have been able to achieve: In the second picture, the divs are shown separately. My goal is to display the incoming data in a single popup like in the first picture, but I am having trouble a ...

Using media queries in VueJS style tags may not have the desired effect

I've encountered an issue with using @media in the style tags of a VueJS component. Surprisingly, styling within the @media query works consistently, while applying styles based on width rules does not seem to have any effect. <template> &l ...

How to retrieve the value of an element within a facebox div with jquery

On my page, I have two div tags displayed below. Whenever I try to retrieve the value of the itemName element using $('#itemName').val();, it always returns the value of the element in the first div (which is blank). Is there a way to access the ...

Tips for Aligning Form Elements in the Middle using Bootstrap

What could be the issue? I can clearly see the container border, indicating the space available for my work. However, when I insert the row (div) and offset (div), the content gets left-justified. <div id="page" class="container" style="border:soli ...

The utilization of CSS within Flask can sometimes lead to a state

Struggling with a python Flask issue here and could really use some help. My CSS is completely out of whack and not displaying correctly at all. Despite setting everything up in static_files and seeing only a 304 code in the terminal, even when trying new ...

Show the elements of an array (that have been read and processed from a text file) on separate lines using JavaScript

Hello, I have the code below where a user can upload a text file. I attempted to display the output in a div after splitting it using the @ character. The array elements stored in variables are correctly displayed with new lines in an alert, but they are p ...

Creating an Image Slideshow on Your Website

I'm looking to create an image slideshow on my website that functions similarly to the one found at . However, I want the images to occupy the entire screen rather than having smaller images like the reference site. Can anyone offer guidance on how t ...

What method can I use to incorporate a custom CSS code in Formfacade to conceal the back button on a Google Form?

Looking for a way to hide the back button on my custom questionnaire created with Google Forms? While there is no built-in option to do this directly on Google Forms, I decided to embed my form into Formfacade. However, I am struggling to find the CSS co ...

Angular 13: Problems arise with custom theme in Angular Material version 13

I've set up a custom theme palette for my project that works perfectly with version ^12.2.13 of Angular Material, but not with ^13.2.3. Here's the SCSS code for my custom theming: my-custom-theme.scss @import '~@angular/material/theming&apo ...

Effortlessly apply CSS styles to multiple cached jQuery variables without redundancy

Hey there, I've got this piece of code written in Javascript for a classic ASP page. Since there are no CSS classes defined, everything is handled within the Javascript itself. var $a= $('#a'), $v= $('#v'), $s= $('#s'), ...

Display a small icon within a checkbox input element inside a label

I have a customized input checkbox that looks like a button, but I want to add a small info icon in the lower right corner using a glyphicon. Currently, this is what I have: <div class="col-sm-4"> <label class ...