Placing a form amidst two div containers

I am delving into the world of CSS and Bootstrap, attempting to recreate a simple layout. However, I'm encountering some challenges.

My goal is to stack 2 divs on top of each other with a form that spans both divs. Can you provide insight on how to achieve this?

Below is the HTML code snippet:

<div class="one">
<div class="container">
<div class="row mx-auto">
<div class="col-sm">
  One of three columns
</div>
<div class="col-sm">
  One of three columns
</div>
<div class="col-sm">
  One of three columns
</div>
</div>
</div>
</div>

<div class="two">
<div class="container">
<div class="row">
<div class="col-sm">
  One of three columns
</div>
<div class="col-sm">
  One of three columns
</div>
<div class="col-sm">
  One of three columns
</div>
</div>
</div>
</div>

<div class="form">
<form>
<div class="form-group">
<label for="exampleFormControlInput1">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" 
 placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1779767a7257726f767a677b723974787a">[email protected]</a>">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Example select</label>
<select class="form-control" id="exampleFormControlSelect1">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect2">Example multiple select</label>
<select multiple class="form-control" id="exampleFormControlSelect2">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
 </select>
 </div>
 <div class="form-group">
<label for="exampleFormControlTextarea1">Example textarea</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"> 
</textarea>
</div>
</form></div>

CSS :

.one {
height: 50vh;
background-color : black;
color : white;
}

.two {
height: 50vh;
background-color : red;
color : white;
}

.form {
width: 30%;
}

Feel free to view the basic example put together in Codepen here:

https://codepen.io/JeremyLemer1/pen/MWgKXzL

Attached is a sample image demonstrating the desired layout:

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

Answer №1

Here is a suggestion for you to try:

.bigdiv {
  height: 300px;
  background: black;
  color: white;
}
.smalldiv {
  width: 250px;
  height: 400px;
  background: orange;
  float: right;
  margin-right:10px;
  transform: translateY(-50%);
  /*
  you can use margin-top:-50px; for browser compatibility
  margin top shoult be -(half of div height);
  
  */
}

.bigdiv1 {
  height: 300px;
  background: darkblue;
  border: 6px solid black;
  color: white;
}
  <div class='wrapper'>
    <div class='bigdiv'>
      <p> Random Text</p>
      <p>Lorem Ipsum</p>
    </div>
    <div class='smalldiv'>
        <form>
            <div class="form-group">
            <label for="exampleFormControlInput1">Email address</label>
            <input type="email" class="form-control" id="exampleFormControlInput1" 
             placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="741a15191134110c15190418115a171b19">[email protected]</a>">
            </div>
            <div class="form-group">
            <label for="exampleFormControlSelect1">Example select</label>
            <select class="form-control" id="exampleFormControlSelect1">
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
            </select>
            </div>
            <div class="form-group">
            <label for="exampleFormControlSelect2">Example multiple select</label>
            <select multiple class="form-control" id="exampleFormControlSelect2">
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
             </select>
             </div>
             <div class="form-group">
            <label for="exampleFormControlTextarea1">Example textarea</label>
            <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"> 
            </textarea>
            </div>
            </form>
    </div>
    <div class='bigdiv1'>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. In, vel iusto. Rem, quidem necessitatibus. Earum odit consequuntur veniam sapiente. Debitis possimus distinctio minus culpa velit corporis, repellendus nihil perferendis cum quam illum dignissimos in nulla atque odit pariatur, eaque praesentium reprehenderit molestias adipisci quibusdam dolorum perspiciatis quos dicta? Recusandae, voluptas dolorem pariatur autem maiores dicta accusamus quis dolorum, alias, voluptatem tempora beatae saepe o  </p>
    </div>
  
  </div> 

Answer №2

How about exploring the potential of using CSS to achieve this? Utilizing position absolute could be the solution you're looking for.

.form {
    width: 30%;
    position: absolute;
    top: 50%;
    right: 5%;
    transform: translateY(-50%);
}

Answer №3

CSS grid can effectively tackle these types of challenges. Below is a simple solution I modified from your Codepen example:

.parent {
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 50vh;
}

.one {
  height: 50vh;
  background-color: black;
  color: white;

}

.two {
  height: 50vh;
  background-color: red;
  color: white;
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.form {
  width: 30%;
}

Instead of applying the grid layout to the body directly, consider creating a parent div as Grid works best in a parent/child structure.

<div class="parent">
 <div class="one">
  <div class="container">
  <div class="row mx-auto">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>
</div>

<div class="two">
  <div class="container">
  <div class="row">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>
</div>

<div class="form">
<form>
  <div class="form-group">
    <label for="exampleFormControlInput1">Email address</label>
    <input type="email" class="form-control" id="exampleFormControlInput1" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a141b171f3a1f021b170a161f54191517">[email protected]</a>">
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect1">Example select</label>
    <select class="form-control" id="exampleFormControlSelect1">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlSelect2">Example multiple select</label>
    <select multiple class="form-control" id="exampleFormControlSelect2">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
  </div>
  <div class="form-group">
    <label for="exampleFormControlTextarea1">Example textarea</label>
    <textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
  </div>
</form></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

What are the steps for encoding a value using jquery serialize?

I attempted to encode all values using the following code: encodeURIComponent($("#customer_details").serialize()); Unfortunately, it did not produce the desired results. Is there a method to retrieve all elements on a form and individually encode each v ...

The secondary menu appears prominently above the primary menu

Here is my .html code : {% load i18n %} <div class="customer-context-menu closed {% if customer.gender == 0 %}male{% else %}female{% endif %}"> <b class="unselectable"> {{ customer.icon }} {{ user.get_full_name }} < ...

When aligning to the right, input box does not wrap

Is there a way to prevent an input box from displaying on a lower line than the menu when using CSS to create a one line menu floated to the right? This is the CSS code being used: <style type="text/css"> #nav { margin:0; padding:0; lis ...

Achieving a 100% height sidebar that remains visible on the screen at all times in Bootstrap

Looking to achieve this specific layout: I want the left col-md-3 to maintain a consistent 100% height and always be visible on the screen - it's going to be a menu. The right side should function normally with scrolling capabilities. Appreciate any ...

Trouble with Bootstrap Modal not closing properly in Chrome and Safari

ISSUE: I'm facing a problem where clicking on the X (font awesome icon) doesn't close the modal popup as expected. https://i.sstatic.net/yXnwA.jpg LIMITED FUNCTIONALITY ON CERTAIN BROWSERS: Currently, the X button for closing the modal works o ...

CSS class for modifying color based on certain conditions

Suppose I have this CSS code: label { color: #AAAAAA; } Can I modify it to include a condition that changes the color to red if the label has the "error" class? I am aware that I can dynamically add the class to the label in HTML, but I am curious if ...

A step-by-step guide to creating a CSS menu using pure HTML markup

I have been working on the CSS for a menu using some HTML code, but I am stuck and uncertain about my next steps. Here is the CSS I have added so far: #menu-my-integra, ul.sub-menu { list-style: none; padding: 0; margin: 0; } #menu-my-integra li ...

Determine the output by applying a constant value to the input

I'm having an issue with a loop function. The goal of the code is to allow users to enter a quantity of goods they want to buy, and then JavaScript calculates a fixed value based on the chosen quantity, which should be printed out. This functionality ...

Tips on positioning the button right next to the bootstrap container

I'm using Bootstrap and facing an issue with aligning a button next to the container in the center, as shown in the image. I know that placing the button inside the container can partially solve this problem, but I prefer not to do so because it will ...

The Angular application is not showing the dynamic title tooltip for the font awesome icon

I am facing an issue where I cannot get the dynamic string to display in the tooltip of a font awesome icon, even though the ng-reflect-title does have a value. Can anyone help me figure out what I might be missing? Could it be something I'm overlook ...

Having trouble with the auto suggest feature in PyCharm with Material Design Lite?

Struggling with setting up a fresh Django project in PyCharm and encountering issues with HTML code autocompletion. I've integrated Material Design Lite as the front-end framework, storing the files in a static folder within the project. I attempted ...

The functionality of scrolling in Angular Material tabs is not functioning properly

I have encountered a challenge while working with angularjs material design. The md-scroll functionality is not working as expected for scrolling up and down, even though it works fine for left and right scrolling. In a tab with a table view, the vertical ...

The dynamically created jQuery form is not triggering the function upon onchange event

Excuse me for troubling you, but I'm having trouble understanding why the function "fileUpload()" is not being triggered when I click the input button. After some investigation, I've discovered that the issue lies with the dynamically generated ...

When the height of the first div increases, make sure the second div gets pushed down

Currently, I am working on creating accordion buttons that are wrapped within a div container. The goal is to keep them in a grid layout with 2 columns like the image below: https://i.sstatic.net/SmfYx.png However, when one of the accordion buttons is op ...

Unable to eliminate the default styling of Material UI table using an external CSS file

Currently, I am incorporating a Material Ui table into my project. My goal is to eliminate the border and adjust the padding of the table. Upon investigation, I came across a default className for material ui table known as MuiTableCell-root-40. Below is t ...

Tips for Maintaining the Execution of a JavaScript Function Within a Class until the Browser Window is Closed (Web Development)

The title might be a little confusing, so let me clarify here: I have implemented a popup that appears in the bottom right corner of a specific page on my website. The popup is working as intended (it shows up when the page is initially opened and can be ...

How can I access a nested FormArray in Angular?

I have a situation where I am trying to access the second FormArray inside another FormArray. Here is an excerpt from my component: registrationForm = new FormGroup({ registrations: new FormArray([this.patchRegistrationValues()]) }); patchRegistrati ...

Exploring the world of sass with compound mathematical statements

There's a slight issue that I'd like to circumvent. $var: 30px; font: 25px/25px font,font,font; //Works font: ($var - 5)/($var - 5) font, font, font; //Works not font: ($var - 5px)/($var - 5px) font, font, font; //Works no ...

OpenStreetMap is failing to display the full map within the designated div

Here is the code snippet for displaying a map when clicking on a Span text, but not showing it in full: var latitude = document.querySelector('#lati').value; var longitude = document.querySelector('#longi').value; var open_address = doc ...

IE is failing to display the textarea, but it is successfully getting submitted

I've written a function in jQuery and JavaScript that generates a form element: createEmail: function(title){ var $emailForm = $('<form>',{action: 'sendEmail.php', id: 'emailForm'}); var $table = $( ...