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

unusual behavior observed in addEventListener

I have recently delved into learning about the DOM. I have a project in mind where I want to create a website with buttons that, when clicked, play different drum sounds. As part of my experimentation with JavaScript, I wanted to explore the this keyword. ...

What is the process for incorporating multiple HTML pages into an Ionic hybrid mobile application?

Struggling to combine my sign in and sign up pages into a single index.html page. I'm currently working on a project involving Hybrid mobile app development. ...

Using a combination of jQuery and JavaScript to switch image tags between different classes

I'm really struggling with this issue and could use some guidance. Essentially, I have a code that should change the class of an img tag when a user clicks on a div element. Let's take a look at the HTML structure: <li><img src ...

Why isn't my API's JSON Response showing up in PHP?

Having trouble displaying the JSON response from an API call in PHP. Despite confirming that the server, IP settings, and API status are all fine on the provider's end, I am unable to identify the problem. This is how I'm handling the PHP part: ...

Step-by-step guide on arranging/placing/styling two div elements next to each other

I'm facing an issue with my CSS and HTML. I can't seem to get the 2 footer items to display on the same line. Is there a problem with how I've structured my divs and styles? Any suggestions for improving the code are greatly appreciated. I& ...

Is there a way to showcase a row of images when a button is clicked?

I am looking to create a functionality where pressing one of the buttons shown in the image below will toggle visibility of specific sections containing 3 images each. For example, clicking on "Tapas" will only display tapas images and hide main course ima ...

What is the most effective method for developing and hosting a Python web application that can securely collect user input and store it in SQL databases?

Currently, I am embarking on a project to streamline data entry for myself. I have SQL tables set up in an Azure database, and I can effortlessly write Python code to add data to them. However, my next endeavor is to develop a web application that allows ...

Setting a minimum height for bars on a graph can be achieved by adjusting the

I need assistance with my graph display. Currently, the graphs are not showing when the value is less than a certain point. I would like to set a minimum height so that they can be displayed regardless of the value. My graphs are being generated using cha ...

The issue of overflowing scroll functionality appears to be malfunctioning

.main-content{ height: 100%; width: 60%; min-height: 800px; background-color: white; border-radius: 5px; margin-left: 1%; border: solid 1px black; } .profile-banner{ display: flex; flex-direction: row; justify-content: space-between; ...

Ensuring my website doesn't load within an iframe using PHP

I attempted to prevent my site from loading in other locations, but unfortunately, my efforts were unsuccessful even after using the following code. <?php header(X-Frame-Options: allow-from https://example.com); header(X-Frame-Options: deny); ?> Is ...

Trying to arrange HTML elements in a diagonal configuration while ensuring they are all uniform in size

My goal is to create an attractive splash page with diagonal, circular links that are all the same size. The <p>'s will function as the links, but I'm struggling to figure out how to make them all diagonal and uniform in size. I've ex ...

Pattern matching excluding "two or more" white spaces

Looking for a unique regular expression that meets the following criteria: No spaces allowed at the beginning or end of a line Only one space permitted between words The previous attempt using "^[АЯ-Ёа-яё0-9' ']+$" didn't q ...

Strategies for limiting a table row in JavaScript or jQuery without utilizing the style tag or class attribute for that specific row

I am looking for a way to limit the display of records in a table. Currently, I can restrict the table rows using the style property, but this causes UI issues such as missing mouse-over effects for the entire row. I need to ensure that mouse-over functi ...

Manipulating DropDownList Attributes in ASP.NET using JavaScript

I am facing an issue with populating a Dropdownlist control on my ASCX page. <asp:DropDownList ID="demoddl" runat="server" onchange="apply(this.options[this.selectedIndex].value,event)" onclick="borderColorChange(this.id, 'Click')" onblur="bo ...

Adjusting diagram size based on screen width using Bootstrap and jQuery

I recently created a diagram that adjusts its size according to the screen width. However, when I implemented this code on my page, I encountered an issue where the final circle or glyph would drop to the next line instead of staying on the same line as in ...

Is there a way for me to prioritize the sidebar over the main content on the page

My theme is efficient and visually appealing, but there's one issue with the mobile layout - it displays the sidebar after the content. How can I rearrange this in my theme so that the sidebar appears before the content? Thanks for your help! ...

Is there a way to insert a colored square into a <button> tag rather than text?

Looking for help with the following HTML: <button name="darkBlue" onclick="setThemeColor(this.name)">Blue</button> <button name="black" onclick="setThemeColor(this.name)">Black</button> I'm interested in replacing the text on ...

Creating a dynamic design with a responsive background image and three columns of engaging content placed on top using Bootstrap

I'm struggling to translate a design mockup into Bootstrap 3.3.6 Here is an image showcasing the concept I am aiming for: The blue background represents an image, with grey text boxes overlaid on top (one of which includes a form). The entire layout ...

The transparent overlay div does not activate when clicking on a button in Internet Explorer 10

While tidying up my CSS and JavaScript, I may have gone a bit overboard. The code seems to work fine on Chrome, Safari, and Firefox, but it's causing chaos in IE10. Check out the code here <div id="bgmbutton1"> <img id="button1" src ...

Dynamic content cannot have classes added to them using jQuery

When adding content dynamically, it is necessary to use an event handler for a parent element using on(). However, I am facing an issue where the class added with addClass on dynamically generated content disappears immediately. Let's take a look at ...