Arranging Div Elements in a Specific Layout

I am currently experimenting with http://jsfiddle.net/ngZdg/

My main goal is to create a parallax website, but I am facing some challenges with the initial layout. I am aiming for the following design:

-------------------------------------
|                                    |
|                                    |
|           ______  ______           |
|           |       |     |          |
|           |       |     |          |
|           ______  ______           |
|                   |     |          |
|                   |     |          |
|                   ______           |
|                                    |
-------------------------------------

Does anyone have any suggestions?

Answer №1

Check out this link:

@charset"utf-8";
 #main {
    background-color:pink;
    width:1280px;
    height:100%;
    position:absolute;
}
#chapter1 {
    background: blue;
    width:90%;
    height:90%;
}
#chapter1_1 {
    background-color:red;
    width:100px;
    height:100px;
    left:100px;
    top:50px;
    position:absolute;    
}
#chapter1_2 {
    background-color:yellow;
    width:100px;
    height:100px;
    left:205px;
    top:50px;
    position:absolute;
}
#chapter1_3 {
    background-color:green;
    width:100px;
    height:100px;
    top:155px;
    left:205px;
    position: absolute;
}

Don't forget to properly close your <DIV> tags.

<div class="whatever" />

Remember, it should be like this:

<div class="whatever"></div>

Answer №2

Your closure of the div tags in the fiddle was incorrect, resulting in a layout similar to your diagram.

<div id="main">
    <div id="chapter1">
        <div id="chapter1_1"></div>
        <div id="chapter1_2"></div>
        <div id="chapter1_3"></div>
    </div>
</div>

CSS:

html, body {
    height:100%;
    width:100%;
    margin:0;
    padding:0;
} 
#main {
    background-color:#00FF00;
    width:100%;
    height:100%;
    /*position:absolute;
    left:50%;
    margin-left:-640px;*/
}
#chapter1 {
    background: blue;
    height:100%;
    position:relative;
    width:100%
}
#chapter1_1,
#chapter1_2,
#chapter1_3 {
    height:20%;
    width:20%;
    position:absolute;
}
#chapter1_1 {
    background-color:red;
    top:10%;
    left:30%;    
}
#chapter1_2 {
    background-color:yellow;
    left:50%;
    top:10%;
}
#chapter1_3 {
    background-color:green;
    top:30%;
    left:50%;
}

Answer №3

Just made some updates to the fiddle - changed the background to absolute and adjusted the positions of other divs accordingly

If you want to check it out, here's the link: http://jsfiddle.net/MarmeeK/ngZdg/19/

This is how the CSS looks:

@charset"utf-8";
 #main {
    background:pink;
    width:1280px;
    height:900px;
    position:absolute;
    top:0;
    left:0;
    bottom:0;
    margin:0;
    padding:0;
}
#chapter1 {
    margin:100px auto 100px auto;
    background: blue;
    height:500px;
    width:800px;
    padding:100px;
}
#chapter1_1, #chapter1_2, #chapter1_3 {
    width:200px;
    height:200px;
    position:relative;
    display:block;
    margin:0;
    padding:0;
    float:left;
}
#chapter1_1 {
    background-color:red;
    left:100px;
}
#chapter1_2 {
    background-color:yellow;
    left:100px;
}
#chapter1_3 {
    clear:both;// to clear the float to next line.
    background-color:green;
    left:300px;
}

I believe this should work perfectly now! :)

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

Changing the background color completely

Need help with CSS! I have two divs, one with a background color of #000 and the other with a transparent PNG image as the background. I want to override the background color with transparency from the PNG file so that the background doesn't cover th ...

Adjust Element Width Based on Scroll Position

I'm attempting to achieve a similar effect as seen here: (if it doesn't work in Chrome, try using IE). This is the progress I've made so far: http://jsfiddle.net/yuvalsab/op9sg2L2/ HTML <div class="transition_wrapper"> <div ...

Explanation on subtracting the row value from a textbox

Click here to view the image For instance: If I enter a value in the "USED(kl)" textbox, it should subtract that value from the corresponding row where "KILOGRAM/S" is located; Upon clicking the update button, only the specific row should be affected wh ...

A single Modal, Ajax, and data that is continuously refreshed

I'm currently facing a challenge in my project as I try to implement Ajax functionality. Although I'm relatively new to using it, I believe I have a basic understanding of its workings. My website involves collecting form data, posting it to a d ...

What can be done to prevent divs from overlapping? They display properly on a computer browser, but not on mobile devices like phones or tablets

Recently, I took on the task of creating an eBay template for someone. With some assistance and a bit of trial and error, I managed to get it working, albeit with what I like to call "not-so-great" code. However, there is one issue that arises when viewing ...

Trying to display logo using 'content' property in CSS

I've been trying to display a logo on the header of my website, but I'm having trouble getting it to show up. I attempted to set the logo using HTML syntax as well as the following CSS code: .div { content: url (...jpg); } However, both metho ...

Apply SetTimeout exclusively for desktop devices

A website I'm working on has a background video from YouTube using YTPlayer. To enhance the user experience, I have implemented a CSS spinner that displays while the page is loading. However, I noticed that the spinner disappears before the video fini ...

Create a dynamic design with Angular Material's mat-drawer at full height using flexbox, allowing content

Yesterday, I encountered an interesting CSS problem involving the mat-drawer and Angular's router-outlet. My layout consists of a full-page flexbox with two children: a mat-toolbar at the top, and a custom component called app-sidenav at the bottom. T ...

Can you explain the significance of this %s value?

While going through some code, I found this: form method='post' input type='hidden' name='input' value='%s' I'm puzzled about the meaning of %s. I attempted to search online for an answer but couldn't fin ...

Is it important to position elements based solely on the parent container?

My frustration with element positioning persists: <div id="container"> <div id="div1"></div> <div id="div2"></div> <div id="div3"></div> </div> #div1 { right:0; // I want its right border to be 0px from th ...

Reposition picture "overlays" additional HTML components

I am struggling with rotating an image by clicking on a button as the image overlaps the buttons. Can anyone provide guidance on how to achieve this without overlapping? For reference, here is my code and an example: here (http://jsfiddle.net/jj03b17n/5/) ...

Can text be replaced without using a selector?

I am utilizing a JavaScript library to change markdown into HTML code. If I insert <span id="printHello></span> within the markdown content, I can still access it using getElementById() after conversion. However, there is one scenario where th ...

Spacing between Div tags

Struggling with a tricky HTML cross-browser problem. The site was built by multiple people, making it quite messy, but needs to go live as soon as possible! Each of the 4 page layouts on the site are different and handled by separate classes. However, whe ...

Update the appearance of a cell if the value within it is equal to zero

I have discovered a way to achieve this using inputs. input[value="0"] { background-color:#F7ECEC; color:#f00;} Now, I am looking for assistance in applying the same concept to table cells. Can anyone provide guidance? Thank you. ...

Using Geolocation in HTML5 and JavaScript

Currently, I am working on my debut mobile web application and have successfully integrated Google Maps into it using Geolocation JavaScript API version 3. Now, I am looking to add a button that, when clicked by the user, centers the map on my location o ...

Center the span element within Bootstrap 5 button groups

I am experiencing an issue where the span elements in my button groups are not aligning properly. I am looking for a way to align these span elements within the button groups without using fixed widths. Creating a basic web modal with Bootstrap 5 <di ...

Choosing HTML Elements for Audio Playback in HTML5: A Guide to Selecting Elements Without Using Div IDs

When creating an HTML5 player, I am transitioning "from using divs with id's" to "simple HTML elements". Former Scenario (functional) <audio src="track1.mp3" id="audio"></audio> <controls> <play id="play" style="display:none ...

What is the best way to utilize JSONP to display an entire HTML code with an alert?

When I attempt to use cross-domain ajax to retrieve the entire HTML page code, I keep receiving a failed message. The console log shows: "Uncaught SyntaxError: Unexpected token <" Below is my AJAX function: function fetchData(){ var url = documen ...

Leveraging ternary operators within HTML elements

Currently, I am utilizing the Vue.js framework to create a dynamic list that updates based on two different list objects. My main objective is to adjust the border of the list cards depending on a specific condition. Below are the defined cards: <li ...

Instructions for implementing tooltips on a pie chart slice when hovering with the mouse pointer, using the canvas

var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var cw = canvas.width; var ch = canvas.height; ctx.lineWidth = 2; ctx.font = '14px verdana'; var PI2 = Math.PI * 2; var myColor = ["Gr ...