FlexBox filling in the gaps

Looking at the image below, I have set up a flexbox layout with a sidebar on the left, a main area in the center, and a small login area to the right.

The fixed heights are as follows: the left sidebar is 600px, the main area is 100vh, and the right sidebar is 200px.

My question is whether it's possible to use flexbox to fill the blank space on the right, below the green area, with the content from the main area. Is this achievable with flexbox or should I consider a different approach for this layout?

I essentially want the red content from the main area to flow beneath the green area.

https://i.sstatic.net/4fii3.png

.main {
  display: flex;
  flex-wrap: wrap;
  border: 0px solid black;
  height: 100vh;
}

.sidebar {
  background: #F1F1F9;
  flex: 1;
  height: 600px;
}

.mainArea {
  flex: 3;
  background: red;
}

.rightSidebarSmall {
  flex: 1;
  background: green;
  height: 200px;
}
<link href="//fonts.googleapis.com/css?family=Raleway:300,400,600,700" rel="stylesheet">

<div class="main">
  <div class="sidebar">
    <div class="logo">
      <img src="img/sound-wave-icon.png" height="100px" width="140px">
    </div>
    <div class="selectorBar">
    </div>
    <div class="menu">
      <ul class="menuOptions">
        <li>Recent Files</li>
        <li>Projects</li>
        <li>Teams</li>
        <li>Archives</li>
      </ul>
    </div>
    <div class="addButton">
      plus icon button
    </div>
    <div class="progressBar">
      uploading 30 files <br> progressBar <br> 7.2mbps 15 secs remaining
    </div>
  </div>
  <div class="mainArea"></div>
  <div class="rightSidebarSmall"></div>
</div>

Answer №1

If you're looking to create a unique and unconventional layout, CSS Grid is the way to go. I've managed to come up with a layout that fits your description perfectly, which I've showcased in a Pen.

Check out the layout on CodePen here

Here's a snippet of the key CSS code:

.main {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
}
.mainArea {
    grid-column: 1 / 6;
    grid-row: 1;
}
.rightSidebarSmall {
    grid-column: 5 / 6;
    grid-row: 1;
}

Answer №2

The optimal solution would be to set the right sidebar to position absolute. By doing this, the main (red area) will cover the entire width and the green area will overlap on top of the red area.

.main {
display: flex;
flex-wrap: wrap;
border: 0px solid black;
height: 100vh;
position:relative;
}
.sidebar {
background: #F1F1F9;
flex: 1;
height: 600px;
}
.mainArea {
flex: 3;
background: red;

}
.rightSidebarSmall {
  position:absolute;
  right:0;
  top:0;
  z-index: 10;
  min-width:100px;
  height:200px;
  background:green;
}
<div class="main">
    <div class="sidebar"></div>
    <div class="mainArea"></div>
    <div class="rightSidebarSmall"></div>
</div>

Hopefully, this solution proves to be beneficial for you :)

Answer №3

A great way to align content to the right is by using the CSS property float: right. Just remember to place the floating element before the rest of your text.

.container {
  width: 50vw;
  height: 50vh;
  position: relative;
}

.box-1 {
    background-color: red;
    float: left;
    width: 100%;
    height: 100%;
    word-break: break-all;
}

.box-2 {
  background-color: green;
  float: right;
  max-width: 150px;
}
<div class="container">
  <div class="box-1">
       <div class="box-2">
        additional text here
      </div>  
      <div>
      The quick brown fox jumps over the lazy dog.
      </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

Position Font Awesome to the right of the text in the list

Hi there, I am currently working on a project where I want to align font awesome icons to the right of my text within a list. My website is in a Right-to-Left (RTL) language and I can't seem to find any resources on how to achieve this. Any help would ...

What is the alternative method for locating a button element in Selenium when it doesn't have an ID, Value, or Type attribute

<button class="btn" style="designs">CLICK ME</button> What is the method to locate this specific element on a web page with Selenium and PhantomJS? ...

Ways to remove the uploaded document

I have been tasked with uploading a file. The file comes with a remove button, which can be pressed to delete it. Below is the code I used: The code snippet is as follows: <div id="main"> <p id="addfile1">Add File</p> <div id ...

Place the child atop the stacked blocks

I need the .square div to always remain at the top, creating a visual effect where it appears as if the following section with its own .square is sliding up and the .square halts precisely at the position of the previous section's square. The code sn ...

Troubleshooting: Issue with Webpack 4 failing to load images in HTML

My webpack configuration seems to be loading images from my SCSS files, but not from the HTML files. Additionally, when I run the BUILD command to deliver my production archives, it doesn't create the "img" folder as expected. As a newcomer to webpack ...

Oddly stacked masonry tiles in a horizontal layout

After spending more than an hour trying to figure it out, searching and reviewing other solutions, I still haven't been able to resolve my issue. My problem is with 5 divs, where the third and fourth div are not stacking up as expected. Instead, the ...

Spin and flip user-submitted images with the power of HTML5 canvas!

I am currently working on a profile upload system where we are implementing image rotation using the HTML5 canvas object with JavaScript. Although the uploaded image is rotating, we are facing issues where parts of the image are being cut off randomly. So ...

Leveraging jQuery to dynamically load an icon based on the content within a <label> tag

I manage a website that dynamically fetches content from a database, with varying contents for each label. For example, one label may be generated as General:, while another may be generated as TV:. My question is, can jQuery be used to replace the text NA ...

Struggling to figure out Visual Studio Code - Having trouble loading images and fonts into my CSS file

It seems like I'm missing something here (just so you know, I'm totally new at this). I attempted to use fonts that are loaded on my computer for my CSS stylesheet (font file in my VSC), but no luck. I also tried using images from my files as bac ...

Link Tag and the Download Functionality in HTML

I'm looking for a way to deactivate the "download" attribute in an anchor tag, like download="false": <a href="https://cdn1.iconfinder.com/data/icons/HTML5/512/HTML_Logo.png" download></a> In my AngularJS application, I want all image fi ...

Personalized design created using v-for

I have an array being passed through v-for and I want to use the values within the "style" attribute. Essentially, I need to append the value from v-for to style:"left"+EachValue+"px", but I'm having trouble with the syntax. I'm unsure if this ap ...

Responsive design for iPad and larger screens - adjusting to different screen sizes

Does anyone know of a CSS code that can effectively target both iPad and desktop devices with a max-width of 768? I attempted the following code, however it seems to only work for desktops: @media only screen and (max-width: 768px) Due to this limitatio ...

Issue with jSignature transitioning properly from display:none to display:block within a multi-page form

After searching through numerous resources, I have been unable to find a solution to my specific issue. I have a multi-page form that incorporates jSignature as the final tab. The structure closely follows the example from the W3Schools website, tailored t ...

What is the best way to incorporate vertical lines into a set of progress bars?

I want to create progress bars with vertical lines representing specific steps within the progression. While I can display progress bars, I am unsure how to incorporate these vertical lines. Does anyone have any suggestions or ideas on how to achieve this? ...

Adjustable Bootstrap Progress Bar - Modify element width on the fly

I have encountered an issue with my progress bars on the webpage. The static HTML version works perfectly fine, but the dynamically created one using jQuery seems to be instantly at 100% without any delay in progression. To illustrate the problem better, ...

Unable to get compatibility mode IE to work as intended

I am facing an issue where I need to showcase a webpage in compatibility mode. Despite using the code below: <meta http-equiv="X-UA-Compatible" content="IE=11"> It seems like this code only functions if compatibility mode is already enabled. In tha ...

Switching the navbar state from a regular mode to a collapsed mode can be done manually

I need help with my navbar design: <nav class="navbar fixed-top navbar-expand-sm navbar-light"> <div class="container-fluid"> <button class="navbar-toggler" type="button" data-bs-toggle=&q ...

When working with Django, I prefer to keep my navbar hidden by not including it in my base template and using the {% block content %} instead

Whenever I include {% extends 'base.html' %}, my navbar appears correctly. However, the moment I add {% block content %} Hello World{% endblock content %}, my navbar disappears and only the text "Hello World" is visible. It seemed simple at first ...

Unable to utilize drop-down menu for input in form

I have created this drop-down menu using HTML: <div id="mySelect" class="select btn-group m-b" data-resize="auto"> <button style="font-weight:700;background-color:#fff;border-style:solid; border-width:2px" type="button" id="expiry_month" ...

Adjusting Height of Left Menu in JQuery Panel

I am facing a challenge with my left menu, created using jQuery panel. Currently, the height of the menu is set to full screen. However, I would like to adjust it so that its height matches the content within (in this case, the ul attribute). Despite tryin ...