Challenge with the desktop sidebar in a responsive design

Disclaimer: Seeking input on how to address this issue kindly suggest another title for editing

Situation

I have a responsive design layout for mobile and desktop with different blocks:

Mobile

| block1         |
| block2         |
| clientInfos    |
| equipmentInfos |
| history        |

Desktop

| clientInfos    | block1  |
| equipmentInfos | block2  |
| -              | history |

Problem

The challenge is determining the best layout option as the page has dynamic height variations in multiple states.

Here are some potential renderings:

| clientInfos    | block1  |
| clientInfos    | block2  |
| clientInfos    | history |
| clientInfos    | -       |
| clientInfos    | -       |
| equipmentInfos | -       |
| clientInfos    | block1  |
| equipmentInfos | block1  |
| -              | block1  |
| -              | block2  |
| -              | history |

The main concern is that clientInfos and equipmentInfos need to be positioned in the middle of the list in the mobile design. Wrapping them in a single div is possible, but not for other items.

Note: The developers follow a mobile-first approach.

Best Solution Attempt

My current attempt involves wrapping clientInfos and equipmentInfos and utilizing a grid-template:

function addSpace (e) {
  e.target.append(document.createElement("br"))
}
.content {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

@media screen and (min-width: 1px) {
 .content {
    display: grid;
    grid-template-areas:
      "clientAndEquipment block1"
      "clientAndEquipment block2"
      "clientAndEquipment history";
  }
}

.block1 { grid-area: block1 }
.block2 { grid-area: block2 }
.clientAndEquipment {
  display: flex;
  flex-direction: column;
  gap: 22px;
  
  grid-area: clientAndEquipment
}
.history { grid-area: history }
.block { background: pink; padding: 5px; }
<div class="content">
  <div class="block1 block">BLOCK1</div>
  <div class="block2 block">BLOCK2</div>
  <div class="clientAndEquipment">
    <div class="client block" onclick="addSpace(event)">CLIENT click here to add spaces</div>
    <div class="equipment block">EQUIPMENT</div>
  </div>
  <div class="history block">HISTORY</div>
</div>

The drawback of this method is that when the client section is too large, it causes other blocks to expand equally in height, which is less than ideal.

Note: Adding an extra "clientAndEquipment -" to the template-grid-areas results in an additional blank line due to gap: 22px, which I want to maintain.

Question

Can you propose a better integration of this design considering the mentioned constraints?

Note: Answers related to JavaScript are not preferred in this case.

Answer №1

I stumbled upon a solution by rearranging my divs using the good old float property.

steps to follow

Arrange all divs that can be aligned to the left at the beginning of the flow (within the .content).

<div class="wrapper">
  <div class="clientInfo left"></div>
  <div class="equipmentInfo left"></div>
  <div class="block1 main"></div>
  <div class="block2 main"></div>
  <div class="history main"></div>
</div>

for mobile

Set the wrapper as flex and apply an order on each item.

.wrapper { display: flex; flex-direction: column; }
.clientInfo { order: 3; }
.equipmentInfo { order: 4; }
.block1 { order: 1; }
.block2 { order: 2; }
.history { order: 5; }

for desktop

Set the wrapper as block then:

// for all desktop media queries ...
.wrapper {
  --sidebar-width: 400px;
  --sidebar-gap: 22px;

  display: block;
}

.left {
  float: left;
  width: var(--sidebar-width);
  margin-right: var(--sidebar-gap);
  clear: both; /* <-- align the left columns */
}

.main {
  margin-left: calc(var(--sidebar-width) + var(--sidebar-gap));
}

And there you have it!

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

Ways to position a single item in the middle of a multi-column layout

I need help with aligning dynamic images in a 2-column layout. What's the best way to center a single image or collapse the columns when there's only one image? Currently, the single image is always placed in the left column. Is there a CSS-only ...

What is the method for retrieving information from a JSON file that has been uploaded?

I am working with some HTML code that looks like this: <input type="file" id="up" /> <input type="submit" id="btn" /> Additionally, I have a JSON file structured as follows: { "name": "Jo ...

Reorganize elements using CSS styling

I have a trio of child divs with the classes span2, span7, and span3. When my browser width drops below 763px, I want them to display in the order span2, span3, and span7. How can I achieve this using CSS? Here is the code snippet I started with: <div ...

Customizing the appearance of Indicators and Paginator in PrimeNG Carousel

I have integrated a carousel using PrimeNG which has the following design here Take note of the style of the carousel indicators and navigators. I want to achieve the default style of indicators/navigators for the carousel as shown here I have included t ...

The picture won't stay within the confines of the container

As I work on my fitness site, I wanted to incorporate a sponsor section. While exploring some code that matched the style of my website, I discovered this snippet below. However, being new to CSS, I struggled with fixing it to ensure that the images fit ...

The process of combining a CssStyleCollection with a System.Web.UI.WebControls.Style

I am working with a list item and trying to apply styles using System.Web.UI.WebControls.Style. However, I noticed that there isn't a MergeStyle option similar to what's available for controls. Instead, there is an Attributes.CssStyle property of ...

Can the href values within <a> tags be altered based on the existing href value?

I am currently in the process of integrating Video JS and Colorbox. My objective is to utilize jQuery to easily modify all href values that contain ".mp4" by replacing it with ".html". This modification will enable the existing code to function smoothly, ...

What steps can I take to stop search engines from crawling and indexing one specific page on my website?

I'm looking for a way to prevent search engines from indexing my imprint page. Is there a method to achieve this? ...

Troubleshooting Angular MIME problems with Microsoft Edge

I'm encountering a problem with Angular where after running ng serve and deploying on localhost, the page loads without any issues. However, when I use ng build and deploy remotely, I encounter a MIME error. Failed to load module script: Expected a ...

How can I effectively retrieve the JWT in a node environment?

I've successfully set up JWT authentication using Node.js. After the user signs in, Node.js generates a JWT and sends it back to be stored in the localStorage. However, I've encountered an issue when trying to access this token within the express ...

Customizing the active state of a Dropdown Item in Bootstrap version 4.5

Recently, I've embarked on the journey of creating my own theme using a combination of SASS and Bootstrap. However, I've hit a little snag when it comes to achieving the desired active appearance for a dropdown item within a navbar. To be complet ...

Styling a Razor view using inline CSS and responsive media queries

I need to add some simple inline styling for print purposes to an .cshtml page I'm working on. I initially tried using the @media print media query, but it is causing issues with my cshtml page. Is there a workaround for this problem? The culprit see ...

Is there a method to categorize distinct "continuing" numbered list items in order to show that they are interconnected?

There is HTML code that I am currently dealing with, and it looks like this: <ol> <li>...</li> </ol> ... content <ol start="2"> <li>...</li> </ol> ... more content <ol start="3"> <li&g ...

Ways to Extract HTML DOM Attributes using Jquery

I am working with an HTML DOM that is saved in a JavaScript Variable. I need to figure out how to retrieve its attributes. For example: <script> //element_html is ajax response var element_html = '<h1 style="" class="app-control " data-order ...

Steps for displaying a bootstrap modal in alignment with the triggering button's position

Recently diving into the world of bootstrap and AngularJs has been quite the learning experience for me. One challenge I encountered was trying to implement a bootstrap modal dialog box to show additional details within a table column. My goal was to hav ...

Instructions on how to load an HTTP file inside a Bootstrap modal

Is it possible to load a file located at an http:// address into a modal window? Something like this: <a class="btn btn-info btn-large" data-toggle="modal" href="#http://localhost/login.html"> <i class="icon-user icon-white"></i> Login ...

Craft a unique parallax effect using Framer Motion's clipping feature

To help visualize my concept, I have sketched it out using Figma. This idea involves a slide transitioning between pages. The goal is to cover the entire page with a sliding effect, and then place a sticker (dubbed the Parallax Box) on top of it. However ...

Is there a way to incorporate a CSS file into this without explicitly mentioning the color?

I have successfully implemented a PHP solution for changing themes with a cookie that remembers the selected theme color when the user leaves the site. However, I now need to switch this functionality to JavaScript while still utilizing the CSS file. How c ...

Recording videos using the Safari Browser

Within my ReactJs application, I have integrated react-multimedia-capture, a package that utilizes navigator.mediaDevices.getUserMedia and the MediaRecorder API to facilitate video recording. While I am successfully able to record videos on Chrome, Safari ...

Tips for swapping out text with a hyperlink using JavaScript

I need to create hyperlinks for certain words in my posts. I found a code snippet that does this: document.body.innerHTML = document.body.innerHTML.replace('Ronaldo', '<a href="www.ronaldo.com">Ronaldo</a>'); Whil ...