Creating three boxes within a single div using standard HTML and CSS

I created this design using Microsoft Paint and now I want to bring it to life using HTML and CSS.

https://i.stack.imgur.com/dwNZi.png

The numbers represent the box numbers in the design.

Here is my attempt at coding this:

HTML file

<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset="utf-8">
  <title>test</title>
  <link rel="stylesheet" type="text/css" href="box.css">

</head>

<body>
  <div id="box1"></div>
  <div id="box2"></div>
  <div id="box3">
    <div id="box4"></div>
    <div id="box5"></div>
    <div id="box6"></div>
    <div id="box7"></div>
    <div id="box8"></div>
  </div>

</body>

</html>

CSS file

html, body {
    margin: 0px;
    height: 100%;
    width: 100%;
}

#box1 {
    border: solid black 3px;
    height: 10%;

}

#box2 {
    border: solid black 3px;
    height: 3%;
}

#box3 {
    border: solid black 3px;
    height: 84%;
}

#box4 {
    border: solid black 1px;
    width: 50%;
    height: 95%; 
    float: left;
    margin: 5px;
}

#box5 {
    border: solid black 1px;
    width: 23%;
    height: 25%;
    float:left;
    margin-left: 10px;
    margin-top: 6px;
}

#box6 {
    border: solid black 1px;
    width: 23%;
    height: 30%;
    float:left;
    margin-top: 10px;
    margin-left: 10px;
}

#box7 {
    border: solid black 1px;
    width: 23%;
    height: 30%;
    float:left;
    margin-top: 10px;
    margin-left: 10px;
}
#box8 {
    (missing code for box8 styling goes here)
}

View how it looks:

https://i.stack.imgur.com/rzexS.png

I'm struggling to get box8 positioned on the right side and setting it as a float right messes up the layout. Also, the boxes inside box3 are inconsistent. When I fullscreen the page, the boxes move to the right side instead of staying put. I tried using percentages for responsiveness but it didn't work as expected. Can anyone provide guidance on how to achieve this design?

Answer №1

To create a grid layout using flexbox, you will need to utilize wrapper divs and apply different flex-directions to each. This will allow you to achieve the desired grid structure.

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

.box-wrapper { 
  height: 100vh; 
  width: 100vw; 
  display: flex; 
  flex-direction: column;
}

#box1 {
  padding:10px;
  height:30px; 
  line-height:30px;
  border: solid 1px red
}

#box2 { 
  height: 15px;
  padding: 8px;
  border: solid 1px blue
}

#box3 { 
  padding: 10px;
  flex-grow:1; 
  display: flex;
  flex-direction: row;
  border: solid 1px green
} 

#box4 {
  flex-grow:2; 
  border: solid 1px orange
} 

.middle-column {
  flex-grow:1; 
  display: flex; 
  flex-direction: column;
  
} 

.middle-column div{ 
  flex-grow:1;
  margin: 0 8px;
  border: solid 1px #6e6e6e;
} 

.middle-column div + div { 
  margin-top: 8px
} 

#box8 { 
  flex-grow:1;
  border: solid 1px black
}
<div class="box-wrapper">
  <div id="box1">1</div>
  <div id="box2">2</div>
  <div id="box3">
    <div id="box4">4</div>
    <div class="middle-column"> 
      <div id="box5">5</div>
      <div id="box6">6</div>
      <div id="box7">7</div>
    </div> 
    <div id="box8">8</div> 
  </div>
</div

https://i.stack.imgur.com/C68gV.png

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 is the best way to eliminate the "onclick" attribute from an HTML element using JavaScript?

Is there a way to make my code only execute the onlick function after a button is pressed? I want to prevent any action from happening before that. <!-- deactivate onclick function --> <div class="boardsection2" id="2_8_7" oncl ...

Adjust image size dynamically while keeping the original aspect ratio

Is there a way to scale variable portrait and landscape images dynamically to fit proportionally within a browser window? You can find my current image resizing attempt here: http://jsfiddle.net/6pnCH/4/ I would like the image to be already scaled vertic ...

What is the method for changing the color of a specific section of a header?

My header design consists of two lists of buttons, one on the left and one on the right. I am looking to customize the background color of the "Sign Up" button to make it stand out. Below is an example of what I want and the current design of my header alo ...

How can I utilize CSS shapes to create clickable images?

I'm facing a challenge in making an input field and button functional even when they are positioned behind a uniquely shaped PNG image. https://i.stack.imgur.com/eOg0N.jpg Initially, I believed that by applying a shape to the image, it would automat ...

Disable, Hide, or Remove Specific Options in a Single Dropdown Selection

A challenge I am facing involves creating a form with multiple select options that need to be ranked by the user from 1-8. However, I am encountering some difficulties in hiding, removing, or disabling certain select options. Below is an excerpt from my f ...

retrieve the value of a text form using jQuery and its corresponding id

I need help with a basic HTML form that includes jQuery. My goal is to: 1) Retrieve the value into a JavaScript variable. 2) Send it as JSON to a server. Here is the form: <div data-role="main" class="ui-content"> <data=role "form" ...

Ways to turn off hover highlighting

Is there a way to disable the highlighting effect of the <select> element in HTML? When you hover over items in the dropdown list, a blue color strip moves with your mouse. I need to find a way to get rid of this effect. Here is an example of the c ...

Interactive text animation triggered by a click

jQuery ( function ( $ ) { console.log(">>Testing animation"); $('a.loveit').on('click',function(event){ event.preventDefault(); var text = $(this).find('div.love-text'); ...

Exploring how CSS affects backgrounds in the Google Chrome browser

Having an issue with the background on my website. In Firefox and other browsers, the background appears much lighter and whiter compared to Chrome. This is the CSS code for my background: body {background:#ffffff url(../../images/background.jpg); direct ...

spark of unique substance

Having trouble with cycle2 as all images are briefly displayed when the page loads. I tried the recommended solution http://jquery.malsup.com/cycle/faq.html but it didn't stop the flashing, indicating a different issue: The suggested fix for Cycle is ...

What is the best way to remove a CSS style using JavaScript?

For my website automation using Selenium, I encountered a challenging dropdown that was not the standard native one but a custom-designed version. To tackle this issue, I needed to set its CSS class to hidden in order to access the native functionality smo ...

retrieving a date from a different source and displaying it in a date

Is there a way to ensure that the date format in an input of type date always follows the dd/MM/yyyy Brazilian pattern, regardless of the computer or browser specifications? <div class="input-group input-group text-center in ...

If the URL matches a specific path, then append a parameter

I've created a script that adds a parameter to a URL based on specific subfolders. For example, if the URL contains /de, it will add ?_sft_language=german. However, I'm encountering an issue where the code is running multiple times instead of jus ...

Interpreting HTML using a PHP script and running PHP commands embedded in the file

Does anyone know how to execute PHP code within an HTML file that is being opened inside a PHP file? Here's the scenario: I have an HTML file structured like this: <html> <head> <title></title> </head> ...

Navigating through pages using Jquery's show and hide functionality

How come my item is not returning? I used the .show() method on the item. <div id="back">< back</div> <div class="item">item</div> <div class="content">My content</div> $(function(){ $('.item').on(&apo ...

Incorporating Dynamic Javascript: A Step-by-Step Guide

I came across a select object that looks like this: <select id="mySelect" onchange = "start()" > <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> < ...

Adjusting CSS Div Blocks for Different Screen Sizes

I am currently working on designing a page layout that includes two sidebars and a main article area. My goal is to have the sidebars stack vertically beside the main area when viewed on a tablet or phone, with both eventually moving below it. However, I a ...

Utilize CSS to break through a backdrop

I have come across a rather peculiar question, and I'd like to elaborate with a code snippet: .container { width: 200px; height: 200px; background: rgba(200, 200, 200, .87); } .pin { position: absolute; left: 50px; top: 20px; } .overl ...

What is the Significance of the Height in This Sample Menu?

I came across this interesting menu sample on W3Schools while working on my MVC layout page. My menu was looking messy, and I really liked the clean look of this one. When I pasted it into my website, it worked perfectly, but I'm puzzled about how it& ...

Ways to embed an HTML file into another HTML document

I have been attempting to include a footer.htm file in my index.htm document without success. Below is the code I am using. index.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.d ...