What are the different ways to position div containers using CSS?

So I have multiple div sections on my webpage, and they are arranged vertically in the following manner: However, I would like them to appear more like this: This is the structure of my HTML:

<div id="main">
            <div id="header">
            </div>
            <div id="content">
                <div id="game" class="box">
                    <canvas data-processing-sources="hello-web.pde"></canvas>
                </div>
                <div id="desc_down"> <!-- Description and Downloads -->
                    <div id="desc" class="box"> <!-- Description -->

                    </div>
                    <div id="down"> <!-- Downloads -->
                        <div id="windows" class="box">
                        </div>
                        <div id="mac" class="box">
                        </div>
                        <div id="linux" class="box">
                        </div>
                        <div id="code" class="box">
                        </div>
                        <div id="info" class="box">
                        </div>
                    </div>
                </div>
                <div id="screenshots" class="box">

                </div>
                <div id="tech_about">
                    <div id="tech" class="box">

                    </div>
                    <div id="about" class="box">

                    </div>
                </div>
            </div>
        </div>
    <div>

and this is my CSS:

#main {
    max-width: 1280px;
    width: 90%;
    margin: 0 auto;
    background-color: #b0e0e6; /* temporary color */
}

#header, #content, #game, #desc_down, #screenshots, #tech_about, #info {
    width: 100%;
}
#desc {
    width: 60%;
}
#down {
    width: 40%;
}
#windows, #mac, #linux, #code {
    width: 50%;
}
#about {
    width: 45%;
}
#tech {
    width: 50%;
}
.box {
    background-color: #FFFFFF;
    border: 5px solid;
    border-color: #000000;
    height: 200px;
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
}

The heights of these boxes may vary. I'm looking for guidance on how to achieve the desired appearance for my website. Thank you.

Answer №1

Set them to have the CSS property float:left or display:inline-block. Alternatively, you can opt for a more efficient solution like utilizing the Bootstrap Grid system.

Answer №2

There are countless methods for arranging your content. Here is a demonstration of what can be accomplished utilizing the concept of floating elements.

See an instance!

HTML

<div id="container">
    <div id="header"></div>
    <div id="firstPane"></div>
        <div class="smallPane"></div>
        <div class="smallPane"></div>
        <div class="smallPane"></div>
        <div class="smallPane"></div>
        <div id="wideSmallPane"></div>
    <div id="afterSmallPanes"></div>
</div>

CSS

#container {
    width: 900px;
    margin: 0 auto;
}
#header {
    height: 250px;
    background: #00F;
}
#firstPane {
    width: 450px;
    height: 600px;
    background: #111;
    float: left;
}
.smallPane {
    float: left;
    width: 220px;
    height: 230px;
    background: #CCC;
    border: dashed 2px #222;
}
#wideSmallPane {
    float: left;
    background: #F00;
    border: dashed 2px #222;
    height: 110px;
    background: #CCC;
    width: 440px;
}
#afterSmallPanes {
    height: 400px;
    background: #00F;
    clear: left;
}

Answer №3

It's quite straightforward. Define the desired width for the wrapper div (which contains these multiple div elements).

Next, apply the float:left property to all of the contained divs.

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

Applying a class change in Vue.js upon mounting

How can I make a button element with a .hover property trigger the hover animation as soon as the page loads? I want to apply a class to the button when the page is mounted and then remove it later. What is the best approach for this? I considered using a ...

Steps to selectively enable or disable checkboxes in a dynamic table depending on a dropdown selection

I'm currently facing an issue with a dynamically generated HTML table from a JSON file. Each row in the table consists of a dropdown list and a checkbox. I need the checkbox to be disabled when the default value is selected in the dropdown, and enable ...

Sending JSON Data over URL

I am facing a challenge with passing data between two HTML files. My initial solution involved sending the data through the URL using the hash and then parsing the link using JSON.parse(window.location.hash.slice(1));. This method worked for a few attempts ...

Instructions for compiling node-sass within the present directory for specific files

In my project, the directory structure looks like this: - folder1 - styles1.scss - folder2 - styles2.scss I want to utilize node-sass through the command line to generate the following output: - folder1 - styles1.scss - styles1.css - folder2 ...

Having trouble getting my local website to load the CSS stylesheet through Express and Node.js in my browser

https://i.stack.imgur.com/qpsQI.png https://i.stack.imgur.com/l3wAJ.png Here is the app.js screenshot: https://i.stack.imgur.com/l3wAJ.png I have experimented with different combinations of href and express.static(""); addresses. However, I am ...

Leveraging JavaScript to create a horizontal divider

Just a quick question - how can I create a horizontal line in Javascript that has the same customization options as the HTML <hr> tag? I need to be able to specify the color and thickness of the line. I am working on a website where I have to includ ...

CSS Navigation Menu - Submenu displaying above main link

<div id="header"> <div class="cont"> <div id="banner"> <div id="nav"> <ul> <li><a href="index.htm">home</a></li> <li><a href="work.html">Works»</a> <ul> ...

What steps can I take to make sure that the content on my website is properly sized to fit within the browser window?

I'm currently working on a website project for my college assignment and I could really use some assistance with a significant issue that I've encountered. Whenever I open the html file of my website on my MacBook, which has a screen resolution ...

.htaccess 404 not redirecting properly

I need help with the following code snippet: # Keep this line intact for mod_rewrite rules to function properly RewriteBase / ErrorDocument 404 /errors/404.php Despite having the file 404.php in the errors folder, it doesn't seem to be working as ...

Performance Issues Arise with Rapid Clicking [jQuery]

Having trouble with a gallery script I created that includes thumbnails, a large image, and navigation arrows. When you rapidly click on thumbnails or arrows during the transition, it causes delays in the process. The more clicks you make, the more noticea ...

Overriding makeStyles CSS in Material UI Styling

When creating classes using makeStyles and useClasses, I've noticed that MUI CSS tends to take precedence over my custom styles unless I use the '!important' rule. Is there a way to override MUI styles without having to rely on '!import ...

In Chrome, the `Jquery $('input[name=""]').change(function will not be triggered unless there is an unhandled error following it

Here is a script that I've created to make certain inputs dependent on the selection of a radio button. The 'parent' input in this case is determined by the radio button choice. Upon document load, the script initially hides parent divs of ...

How can I prevent the same JavaScript from loading twice in PHP, JavaScript, and HTML when using `<script>'?

Is there a PHP equivalent of require_once or include_once for JavaScript within the <script> tag? While I understand that <script> is part of HTML, I'm curious if such functionality exists in either PHP or HTML. I am looking to avoid load ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

If the value stored in $_SESSION['uname'] is not "teacher", redirect back to the homepage

I am currently working on a webpage and I want to restrict access to only users with the username "teacher". I came across this code snippet: <?php session_start(); if(!isset($_SESSION['uname'])){ header('location:(main p ...

I am experiencing difficulty with aligning my input boxes to the center in my React-Native

Just a heads up, this is my first time diving into the world of React Native, so bear with me as I try to figure things out. Please be kind if my question seems silly... Here's a snapshot of what I currently have: https://i.stack.imgur.com/VWGFm.png ...

Display a variety of body background images depending on the user's selection

Is it possible to change the background of the page when an option is selected from a dropdown menu? Additionally, can this be achieved with a smooth fade in and fade out animation? Here is a code example on CodePen. body ...

Struggling with integrating Bootstrap 4 Modals in Angular 2 environment

I attempted to incorporate a modal from into my navbar, but nothing happens when I click on it. <div class="pos-f-t fixed-top header"> <nav class="navbar navbar-inverse bg-inverse navbar-toggleable-md"> <button class="navbar- ...

Retain the jQuery dropdown menu in an open state while navigating to a different webpage on the

I am encountering an issue with a drop-down menu on my website. Whenever I click on a submenu link, the new page opens but the menu automatically closes. However, I want the active menu to remain open even on the new page. To solve this problem, I believe ...

Customize the layout of menu icon in HTML/CSS using FlexBox Grid

Recently, I have encountered an issue with the position of a menu icon on my website. The icon is displayed when the window reaches a certain size, but it is not aligned properly on the right side of the site. Ideally, I would like to use the "right" prope ...