How can I achieve this particular design using flexbox?

Check out the image here: . I'm struggling to understand the examples and live flex configurators. Are they only showing simple examples, or am I just not grasping it?

Is it possible for me to use media queries to hide a4 when the screen is less than 800px wide?

I have always used float, so flex seems "different" to me. I would like to gain a better understanding of it, so any assistance is welcome.

Here's a flex-specific example for reference.

Answer №1

Implementing display: flex on a container will cause its child elements to be displayed in a flex layout. In this particular setup, it is recommended to wrap the elements when the width of the current row is already filled.

The header and footer should have a width: 100%, occupying an entire row. #a3 and #a4 should utilize flex: 1 to evenly distribute the width of their row, each taking up 50%.

div.flex-container{
  width: 200px;
  height: 300px;
  background-color: black;
  
  display: flex;
  flex-flow: row wrap;
}

#a1, #a2{
  width: 100%;
}

#a3, #a4{
  flex: 1;
}

#a5, #a6, #a7{
  height: 50px;
  width: 80%;
  margin: auto;
  margin-bottom: 1rem;
}

/* Example styles */
div{
  text-align: center;
}
#a1{
  background-color: red;
}
#a2{
  background-color: limegreen;
}
#a3{
  background-color: royalblue;
}
#a4{
  background-color: cyan;
}
#a5, #a6, #a7{
  background-color: fuchsia;
}
<div class="flex-container">
  <div id="a1">a1</div>
  <div id="a3">a3</div>
   <div id="a4">a4
    <div id="a5">a5</div>
    <div id="a6">a6</div>
    <div id="a7">a7</div>
  </div>
  <div id="a2">a2</div>
</div>

You can also incorporate media queries as needed.

div.flex-container{
  width: 200px;
  height: 300px;
  background-color: black;
  
  display: flex;
  flex-flow: row wrap;
}

#a1, #a2{
  width: 100%;
}

#a3, #a4{
  flex: 1;
}

#a5, #a6, #a7{
  height: 50px;
  width: 80%;
  margin: auto;
  margin-bottom: 1rem;
}

@media (max-width: 800px){
  #a4{
    display: none;
  }
}

/* Example styles */
div{
  text-align: center;
}
#a1{
  background-color: red;
}
#a2{
  background-color: limegreen;
}
#a3{
  background-color: royalblue;
}
#a4{
  background-color: cyan;
}
#a5, #a6, #a7{
  background-color: fuchsia;
}
<div class="flex-container">
  <div id="a1">a1</div>
  <div id="a3">a3</div>
  <div id="a4">a4
    <div id="a5">a5</div>
    <div id="a6">a6</div>
    <div id="a7">a7</div>
  </div>
  <div id="a2>a2</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

Is there a way to verify the identity of two fields using an external script such as "signup.js"?

My current project involves working with Electron, and it consists of three essential files. The first file is index.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="styles ...

An oversized image creates additional room

I currently have a board that consists of 3 blocks, with each block containing a grid of 25 squares. These squares are 40x40px in size with a margin around them, resulting in an overall size of 220px x 220px. Each square also has some space above and below ...

Is it possible to ensure a div occupies all available space within a column using the vh-100 class in bootstrap?

In the <div class="bg-primary"></div> element, I'm trying to make it take up the remaining empty space without exceeding the vh-100. I've experimented with various solutions but haven't been able to find a fix yet. b ...

What steps can be taken to avoid an input with a width of 100% from overflowing?

I'm facing an issue that needs to be resolved. Currently, I have a group of div elements arranged in a table-like structure with a row and three columns. When these divs reach a maximum width of 768px, the first column is hidden, leaving only the se ...

Is it possible to use font-face in CSS3 to switch fonts for different languages?

Can I replace an Arabic font with a custom one using font-face in CSS3? I've successfully done it with English but I'm not sure if it's the same for foreign languages, so I wanted to check. Also, I feel silly asking this question, but I&apos ...

Having trouble with my CSS hover not functioning properly

I need some help with my code. Can you please take a look and let me know why the hover effect is not working? Thank you! <style> #moreDiscussHome:hover{ background-color: #ffffff; } </style> <a id="moreDiscussHome" style="co ...

Issue with readonly is preventing the ability to alter the font color of the input

I need to change the font color of a disabled input. When it is disabled, it appears gray and I want it to be black instead. I attempted to use readonly but that did not have the desired effect, and now the input is showing [object Object]. Below is my HTM ...

Resetting CSS attributes in Kendo UI Mobile when transitioning between views after removing them with jQuery

Dealing with the flicker of unstyled content in my kendo mobile web app has been a challenge, but I found a solution by using a specific CSS rule within my stylesheet: [data-role="content"] { visibility: hidden; } This effectively hides all ...

Attempting to align content in the middle of the page across all web browsers

I need assistance with centering all the content on my website across different screen sizes and browsers. Currently, everything appears off-center and aligned to the left on various screens I have tested. You can view the HTML and CSS code in this link. H ...

Bootstrap Carousel fails to function properly

I have tried everything, even using code directly from ww3 with added cdn. It worked on bootstrap 4 beta, but the rest of my site is using an earlier version. I'm new at this and hesitant to mix versions unnecessarily. <!DOCTYPE html> <html ...

Apply CSS styles to the checkbox

I am new to CSS and I need help styling a checkbox element. When the user selects one of the checkboxes, I want the background color to change to yellow. Thank you for any assistance you can provide! .radio_toggle { float:left; } .radio_toggle label ...

Discovering the offset location using touchmove

Struggling with a code for dragging/moving an element via touchscreen. The code is functional, but encounters a common issue - unable to drag from the touchpoint itself. Every movement initiates from the edge of the element, no matter where the touch begin ...

Arrange the div and ensure that the external JavaScript file functions properly when the page loads

I am encountering an issue with my JavaScript and CSS code. It works perfectly fine within the fiddle environment but fails to function properly outside of it. Here is the link to the fiddle When I embed the code into an HTML document directly, it does n ...

How can I activate the fancy box from a specific div element?

There are plenty of variations to this question, but none of them seem to help. I am looking for a way to trigger fancybox from a div. Here is the div in question: <div class="port web">Website</div> This particular div has some CSS styles ap ...

Do we always need to incorporate components in Vue.js, even if there are no plans for reuse?

I've been pondering this question for some time now: is it necessary for every component to be reusable? Consider a scenario where we have HTML, CSS, and JavaScript that cannot be reused. For instance, a CRUD table designed specifically for managing u ...

The AppBar is consuming space and obstructing other elements on the

As I dive into React/Material-UI and learn the ropes of CSS, I've come across a challenge with my simple page layout featuring an AppBar. Unfortunately, this AppBar is overlapping the elements that should be positioned below it. In my quest for a sol ...

Tips for enabling both vertical and horizontal scrolling using the mousewheel on a webpage

Our website features a unique scrolling functionality where it starts off vertically and then switches to horizontal once the user reaches the bottom. This allows for a seamless transition between scrolling directions. In addition, users can easily naviga ...

Can you tell me the Bootstrap 4 equivalent class for '.well'?

While using bootstrap-3, the .well class can be utilized to create a rounded border around an element with a gray background color and padding. <div class="well">Basic Well</div> However, it seems that there is no .well class available in boo ...

Issue encountered with jQuery nested hover events and the removeClass() function being triggered on mouseleave

I have a nested list structure that I am working with: <ul class="menu-wrapper"> <li> <a href="#">Menu item</a> <ul class="sub-menu"> <li> < ...

"Enjoying a table header that scrolls freely with autoscroll feature

Resolved - http://jsfiddle.net/CrSpu/11704/ I'm facing an issue with a table that has autoscroll functionality. I am looking to freeze the header of the table when automatic scrolling occurs, or you can test it out using my code pen. I'm uncer ...