Stacking divs one on top of the other

My goal is to design a simple webpage with two full screen background colored divs. On top of these background divs, I want to add two smaller divs where I can input text and place a button underneath to randomize the words (refer to the attached screenshot for reference).

View Screenshot of Desired Layout

I have created the code for the background divs but for some reason, I am struggling to overlay any elements on top of them...

.container {
  height: 100%;
  padding: 0;
  text-align: center
}

.inner {
  width: 50%;
  height: 100%;
  display: inline-block;
}

.inner.left {
  background-color: brown;
}

.inner.right {
  background-color: grey;
}
<div class="container">
  <div class="inner left"></div>
  <div class="inner right"></div>
</div>

Answer №1

Is this the kind of layout you were anticipating?

body,html{
margin:0;
padding:0;
}
.one{
width:50%;
background-color:brown;
float:left;
margin:auto;
height:100vh;
}
.inner_1{
  margin: 0;
  position: absolute;
  top: 50%;
  right:50%;
  width:200px;
  line-height:60px;
  background-color:yellow;
  text-align:center;
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}
.inner_2{
  margin: 0;
  position: absolute;
  top: 50%;
  background-color:#7be0ff;
  width:200px;
  line-height:60px;
  text-align:center;
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}
.two{
width:50%;
background-color:#bebebe;
float:left;
height:100vh;
}
.button{
 margin: 0;
 position: absolute;
 top:70%;
 background-color: #6afa70; /* Green */
 left: 50%;
 -ms-transform: translate( -50%);
 transform: translate(-50%);
 border:none;
 text-decoration: none;
 }
<div class="one">
<div class="inner_1">Div layer on top 1</div>
</div>
<div class="two">
<div class="inner_2">Div layer on top 2</div>
</div>
<input type="button" class="button" value=" Button">

Answer №2

When it comes to aligning the content within div elements vertically, one approach is to utilize a combination of table-cell and float. Here's an example of how you can achieve this:

.container{ 
    position: absolute;
    width: 100%;
    height: 100%;
    padding: 0;
    text-align: center;
 }
.inner{
    width: 50%;
    height: 100%;
    float: left;
}
.inner.left{
    background-color: brown;
}
.inner.right{
    background-color: grey;
}
.inner-sub{
    display: table;
    width: 100%;
    height: 100%;
}
.inner-sub .align{
    position: relative;
    display: table-cell;
    vertical-align: middle;
}
.inner-sub .align .content{
    width: 300px;
    height: 40px;
    background: red;
    float: right;
}
.right .inner-sub .align .content{
    float: left;
}
.button-container button{
    position: absolute;
    right: -28px; /* half of the width of the button */
    height: 20px;
    margin-top: 70px; /* set this depending on how far away you want the button to be from the elements */
}
<div class="container">
    <div class="inner left">
        <div class="inner-sub">
            <div class="align button-container">
                <div class="content">div layed on top 1</div>
                <button>Button</button>
            </div> 
        </div>
    </div>
    <div class="inner right">
        <div class="inner-sub">
            <div class="align">
                <div class="content">div layed on top 2</div>
            </div> 
        </div>
    </div>
</div>

Check out the implementation on JsFiddle: https://jsfiddle.net/nvL6wyoj/2/

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

Choose the option in real-time with Jquery

I'm currently developing a dynamic HTML for Select Option as seen below: item += "<td class='ddl' style='width:40%;'>"; item += "<select>" item += " <option id='list' name='selector' value=" + se ...

Make sure to include the target blank attribute in your custom PHP code for

Is there a way to open a link in a new window? <?php if(get_option_tree('rss')) { ?> <a href="<?php get_option_tree('rss',$theme_options,'true'); ?>" id="rss" title="RSS" class="tt_top"></a><?php } ...

Designing a loading animation with rotating lines converging towards the center to form a circular motion

Check out my code snippet below: .circle { border: 1px solid transparent; border-radius: 50%; width: 100px; overflow: hidden; } .div7 { width: 100px; height: 10px; background: red; color: white; font-weight: bold; positi ...

Utilizing Unicode characters within the content of a pseudo element in data-content

Is there a way to include unicode in the data-content attribute using JQuery for pseudo element content? I'm having trouble with the correct formatting. How can I properly display unicode characters? Currently, all I see is &#x25BC;. a::after { ...

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 ...

My navbar in bootstrap is having trouble staying aligned with the button and search box. What can I do to ensure everything stays in line?

<nav id="NavbarMaster" class="navbar NavCompression"> <!-- style="min-height:100px;" --> <div id="navToggler" class="container-fluid TitleBG TitleHeight"> <div id="navopener" class="Pointer" style="position:fixed;top:0;left:0; ...

Using CSS Zoom / Transform with the iframe Tag in HTML

I'm currently working on embedding a child web page (a plain HTML/PHP file) into a parent web page built on WordPress. The challenge I'm facing is that the parent web page has a width of only 800px, whereas the child web page has a width of appro ...

Guide on validating multiple preselected checkboxes using Angular 8 reactive forms

I have a problem with validating checkboxes in my Angular application. The checkboxes are generated dynamically from an array using ngFor loop, and I want to make sure that at least one checkbox is selected before the form can be submitted. The validatio ...

After attempting to refresh the webpage with the F5 key, I noticed that the jQuery progress bar was not functioning properly. Additionally, the webpage failed to display any

Trying to implement a web loading bar using jQuery on my website was initially successful, but I encountered an issue when reloading the page with F5. The progress bar would not work and the webpage displayed only a white background. Below is the code snip ...

Changing direction of arrow upon dropdown menu opening with JavaScript

I have developed a piece of code that enables users to click on a div in order to reveal a dropdown menu containing radio buttons. My goal is to make the arrows rotate 180 degrees when the dropdown menus are opened, and then return to their original positi ...

Ensure the webpage is set to have a minimum width of 1024 pixels

Is it possible to make a webpage that utilizes bootstrap, Angular 2x, and Scss stop being responsive once the screen width reaches 1024px? I would like the layout to stay fixed at this size and enable horizontal scrolling for users who resize their browser ...

Dropdown element with PrimeNG adorned with a span

I am trying to create a simple form with text inputs and dropdowns. I have successfully implemented the textInput, but I am struggling with the dropdowns. Below is the code that I have so far: <div class="p-grid p-dir-col p-offset-2"> ...

What is the best way to make a black background div that perfectly aligns with another div?

When hovering over an image, I want it to fade out to opacity: 0.4, but instead of fading to white, I would like it to fade to black. To achieve this, I decided to change the background color of the body to black so that the fadeout will be towards black. ...

Tips for making a standout testimonial card?

Apologies for the simplistic inquiry. As a fresh student of a full stack web developer bootcamp, I find myself grappling with this particular challenge. How can I go about creating a testimonial card similar to this one? I've attempted to write code ...

HTML5 Advanced API Integration with Vimeo

After setting up my Vimeo account and app for video upload, I received approval. However, when I attempted to upload a video to the Vimeo server, I encountered difficulties. I am struggling to understand how OAuth functions. Please see below for the co ...

What is the best way to align a div with a fixed width in the center, when it is positioned between two other divs within a parent

I have this HTML (technically JSX) code snippet here: The center div with the class domain-input-parent is supposed to have a fixed width of 400px and stay centered horizontally on the screen. This arrangement ensures that both the domain-label and icon- ...

Setting the background color in the navbar of a Laravel application

I'm having trouble changing the color of my navbar to blue in certain parts. I've tried using background: lightblue;, but for some reason, two sections remain white. How can I make them completely blue? (see screenshot below) Any help would be ap ...

Maximizing Particle Performance Using JavaScript

I am experimenting with creating particles in JavaScript for the first time, and I'm unsure if the code below is optimized. When I generate 100 particles on the screen, there isn't much of an FPS drop noticeable. However, when multiple clicks o ...

Guide on storing images in a designated folder using CodeIgniter

My code is located in view/admin_view2.php <?php echo form_open_multipart('home_admin/createBerita'); ?> <div class="form-group" > <label class="control-label">upload foto</label> <inpu ...

Activate single elements one at a time

If you want to understand the question better, take a look at my code on jsfiddle. Each Div contains only one link. When you click on the link, it sets the Div to active and shows a hidden Div within it. Clicking the link again toggles the active style an ...