Unable to place a div below another div

I am in the process of creating a website for my mother, using my limited knowledge. Despite numerous attempts, I have not been able to achieve the desired outcome.

Currently, the website looks like this:

https://i.stack.imgur.com/ItOcp.jpg

However, I envision it looking like this:

https://i.stack.imgur.com/fWyjo.jpg

Unfortunately, I am facing difficulties in getting it to work as intended. The positioning of the div element is not behaving how I would like it to.

This is the source code I am working with: JsFiddle

The issue seems to be related to this particular section of the code:

 <div class="wrapper_3">
    <div class="main_3">
        3
    </div>
 </div>

I appreciate any assistance you can provide. I am truly struggling to make it work correctly.

Answer №1

To style wrapper_1 and wrapper_2, add float:left; to both elements.

Next, use position:relative; to position wrapper_2 accordingly.

If you need further assistance with CSS syntax, check out the following link: CSS Position Property Here is your updated CSS:

.wrapper_1 {    
  width: 25%;
  display: inline-block;
  position: relative;
  margin-left: 21%;
  clear: both;
  float: left;
}

.wrapper_2 {
  width: 25%;
  display: inline-block;
  position: absolute;
  margin-left: 16px;
  top: 50%;
  float: left;
}

Answer №2

If you want to simplify the process, consider utilizing bootstrap for your website development.

Here is an example of HTML:

<div class="container">
    <div class="row">
        <div class="col-xs-2">
            <div class="logo text-center">logo</div>
        </div>
        <div class="col-xs-offset-4 col-xs-3 box">2</div>
            <div class="col-xs-offset-4 col-xs-3 box">1</div>
    </div>

</div>

CSS styling:

.logo {
    border-top: 1px solid black;
    border-bottom: 1px solid black;
    padding: 15px;
}
.box {
    padding: 60px;
    background-color: red;
    margin-top: 30px;
}

For a live demo of this code, visit here.

To properly implement Bootstrap, make sure to link the bootstrap.css file in your code. You can learn more about linking bootstrap.css by visiting this link and adding the required code to the head section of your file.

Answer №3

Here is the updated version :) I made some changes to your code snippet. Have you considered using relative positioning instead of absolute positioning for a cleaner design?

* { 
  padding: 0; 
  margin: 0; 
}

html, body {
  width: 100%;
  height: 100%;
}

.main {
  position: relative;
  width: 100%;
  height: 100%;
}

.wrapper_logo {
  margin-top: 10px;
  margin-left: 10px;
  width:20%;
  display: inline-block;
  position: relative; /* Changed from absolute */
}

.wrapper_logo:after {
  padding-top: 45%;
  /* 16:9 ratio */
  display: block;
  content: '';
}

.main_logo {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    padding: 10px;
    padding-left: 20px;
    font-size: 30px;
    border-top: 1px solid black;
    border-bottom: 1px solid black;
    color: black;
    vertical-align: middle;
}

.wrapper_1 {
  width: 25%;
  display: inline-block;
  position: relative;
  margin-left: 21%;
  margin-top: 14%;
  clear: both;
}

.wrapper_1:after {
  padding-top: 56.10%;
  /* 16:9 ratio */
  display: block;
  content: '';
  clear: both;
}

.main_1 {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 20px;
  font-size: 30px;
  background-color: deepskyblue;
  color: white;
}

.wrapper_2 {
  width: 25%;
  margin-left:200px;
}

.wrapper_2:after {
  padding-top: 56.10%;
  /* 16:9 ratio */
  display: block;
  content: '';
}

.main_2 {

  padding: 20px;
  font-size: 30px;
  background-color: deepskyblue;
  color: white;
}

.wrapper_3 {
  width: 15%;
  float: left;
  display: inline-block;
  position: relative; /* Changed from absolute */
}

.wrapper_3:after {
  padding-top: 56.10%;
  /* 16:9 ratio */
  display: block;
  content: '';
}

.main_3 {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 20px;
  font-size: 30px;
  background-color: deepskyblue;
  color: white;
}

.three {
  position: absolute; 
  background: green; 
  width: 400px; 
  top: 10px; 
  left: 50px;
}
<!DOCTYPE html>
<div class="main">
    
    <div class="wrapper_logo">
<div class="main_logo">
LOGO
</div>
</div>

        <div class="wrapper_1">
<div class="main_1">
1
    </div>
</div>

<div class="wrapper_2">
<div class="main_2">
2
    </div>
</div>

<!-- <div class="wrapper_3">
<div class="main_3">
3
    </div>
</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

Navigating within fixed-positioned divs

I'm attempting to create something similar to the layout seen on: The desired effect is to have fixed content on the right side, with only the left side scrolling up to a certain point before the entire page scrolls normally. However, in my implement ...

Tips for setting up Greasemonkey to automatically click on an unusual link on a particular website

I'm not a master coder by any means; I can handle some scripts but that's about it. Treat me like a total beginner, please! ;-) I want to automatically expand two specific links on a webpage using a GM Script. On a French dating site in the prof ...

Node-modules CSS

In my React application, I am utilizing CSS modules. By configuring modules:true in my webpack.config.js, I can successfully apply styles from files within my src folder. However, when importing components from node-modules, the corresponding CSS is not be ...

Limit the character input in AngularJS/Ionic to a specific number

I have a text input field that needs to restrict the user from entering more than a specific number of characters. Let's say I only want the user to type 10 characters, and if they try to enter more, the text field should not accept it. It should stop ...

Tips for disabling viewport resizer while accessing the Console panel in Chrome using Control+Shift+J

Currently, I am utilizing the viewport resizer in Chrome to preview how my code appears on various devices. However, I have encountered an issue - whenever I try to access the console using ctrl + shift + j, the viewport resizer opens instead. You can obs ...

"Upon choosing a file using the HTML input file multiple element, a triggered event

After selecting multiple files using the input type="file" HTML element, I am eager to start uploading them. Can you tell me which event I should use to execute code immediately after finalizing my file selection? This is what my HTML code looks like: &l ...

Creating an insert query in Node.js with frontend HTML and connecting it to a PostgreSQL database is a crucial task in web

I am new to working with Node.js, PostgreSQL. Currently, I am tackling the login form code and facing several issues related to the POST method. I am using HTML, Node.js, and PostgreSQL for this project. Please assist me with solving these problems by revi ...

Learn how to dynamically insert data retrieved from a database into a PHP database table

After fetching data in a tabular format from the database, I noticed that three columns of the table are retrieved directly while the remaining two consist of drop-down lists and checkboxes. Now, my challenge is to extract data from the retrieved rows and ...

What is the best way to customize the style of a react.js component upon its creation?

Is there a way to set the style of a react.js component during its creation? Here is a snippet of my code (which I inherited and simplified for clarity) I want to be able to use my LogComponent to display different pages of a Log. However, in certain ins ...

"Use AJAX to dynamically update a div element when a button is clicked with a specific value

I have a calendar that is being displayed server side using PHP. My goal now is to allow users to scroll through the months with two buttons (<< / >>) without having to reload the entire page. I have come across many similar questions and examp ...

Displaying images in Dash Python by utilizing external Javascript

Dear audience, I am looking to incorporate an image on a Python Dash webpage that is created by JavaScript code. For more details, you can refer to the documentation here: . To include this script in a static HTML page, one would typically add the followi ...

Troubleshooting problem with navigation tabs in Bootstrap version 3.x

My bootstrap component nav-tabs works fine on desktop when the page width is larger than necessary for the row. However, on mobile devices, the responsive design doesn't behave as expected and the tabs become misaligned. You can see the issue in the c ...

Preventing HTML entities from expanding in the HTML::TreeBuilder Perl module

Below is a snippet of code to examine: #!/usr/bin/perl use strict; use HTML::TreeBuilder; sub test { my ($content) = @_; my $tree = HTML::TreeBuilder->new; $tree->implicit_tags(0); $tree->no_expand_entities(1); $tree->parse_conte ...

information not visible on the webpage

Recently, I made an alarming discovery on my website. I have implemented two different types of menus - one for the front page (designated as .navbar-inverse) and another for all other pages (.navbar-default). The front page menu is static while the other ...

Is there a way to utilize a Javascript function to incorporate commas into a div tag?

Being new to JavaScript, I have heard about jQuery but I don't know how to use it. Please bear with me as I am not well-versed in this area. :) I am currently importing data dynamically from an Excel database to a website. Everything is working fine ...

Prevent jquery-ui datepicker from opening when the confirmation box is cancelled

Here are the snippets of code I'm currently working with: HTML, Date : <input id="datepicker"> Fare : <input id="fare"> JS, <script> $(function(){ $("#datepicker" ).datepicker({ changeMonth: true, ...

Choosing particular contenteditable divisions using jQuery

Consider the following HTML structure for a specific type of blog post editor: <div class="entry"> <div class="title" contenteditable="true"> <h2>Title goes here</h2> </div> <div class="content" contenteditable ...

Is it possible to replace text on click using CSS instead of jQuery?

My new project involves creating a flashcard system. The idea is that when a question is clicked, it reveals the answer and hides the question. To achieve this, I am currently using the following code: jsFiddle <p id="shown">What is stackoverflow?&l ...

Concealing divisions on a website with CSS styling

In my div, I have some text that I want to hide. <div style='visibility:hidden;' id='emailid'>$email</div> Although the visibility attribute successfully hides the text, it leaves behind empty space on the webpage where th ...

Displaying the information from a nested array of objects in an HTML table through iteration

In the code snippet below, there is an input with a nested array of objects. The main array of objects is called summary and within it, there's a nested array called run_type. let input = { "summary": [ { " ...