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

What is the best approach for managing the popstate event when the URL no longer exists?

When working with html5 popstate, I have two specific goals in mind. Instead of relying on plugins, I am utilizing these two methods: Push State: function contentLoaded(...) { ... window.history.pushState({ pageUrl: url }, url, url); ... } Po ...

Missing sidebar display

Hi there! I am having an issue with my sidebar not appearing correctly when I click on the toggle button. It seems to be moving to the side, but the sidebar itself is blank or transparent. I suspect that the problem lies within my JavaScript file. As a beg ...

Can anyone provide a reference or resource that explains the best scenarios for utilizing display:block, display:inline, and display:inline-block, and the reasons behind their usage?

Can you recommend a quality article discussing the guidelines for using display:block, :inline, and :inline-block in CSS, along with explanations on when to utilize each one? Additionally, in what scenarios should we override the display property through ...

How to access an element inside a div using the eq() method

Within my #img_wrapper, I have multiple pictures each enclosed in a link: <div id="img_wrapper"> <a href="img1.jpg" style="display: none;"> <img src="img1.jpg" /> </a> <a href="img2.jpg" style="display: none;"> &l ...

The function Mediarecorder.start() is experiencing issues on Firefox for Android and is not functioning

Recently, I've been facing a peculiar issue while developing a web application. The purpose of this app is to capture about 10 seconds of video intermittently from the device webcam and then upload it to a server. For this functionality, I utilized th ...

Overflow issue with floating labels in Bootstrap 5 within a grid container

Incorporated within this code snippet are floating selects placed inside a bootstrap grid: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b6bbbba0a7a0a6b5a494e1fae7fae7">[emai ...

A step-by-step guide to creating adorable rounded corners in a DIV element

I'd like to create a stylish rounded corner div on the top-right and top-left edges. I attempted it with the following code: border-top-left-radius: 5em; border-top-right-radius: 5em; Desired look of the div: https://i.stack.imgur.com/EoSvSm.jpg A ...

Issue with zeroLineColor and zeroLineWidth not functioning properly for the x-axis within Chartjs

Looking to customize the width and color of the x-axis in Chartjs? While it's straightforward for the y-axis using zeroLineColor and zeroLineWidth, achieving the same effect for the x-axis seems trickier. If you try adding: ticks: { beginAtZero: tr ...

Utilizing AJAX and JavaScript to generate a table using the AJAX response and placing it within a <div> element

I am currently passing the response of this action in text form, but I would like to display it in a table format. Is there a way to do this? function loadAditivos(){ $('#aditivoAbertoInformacoesTexto').html('<div id="loaderMaior ...

An issue occurred while attempting to hover over the text in the SVG map

I have a United States map. This code contains CSS for styling the map with different colors for each state. It also includes an SVG image of the map and text labels for each state name. However, there is an issue with the hover effect on the state name ...

What is the purpose of applying the two unique class names (root and disabled) to the DOM in order for it to function correctly?

When it comes to customizing components using material-ui, the process can be a bit tricky. Here's how you can do it: const styles = { root: { '&$disabled': { color: 'white', }, }, disabled: {}, // This is i ...

Deactivate the button until the input meets validation criteria using Angular

What I'm trying to achieve is to restrict certain input fields to only accept integer or decimal values. Here's the code snippet that I currently have: <input type="text" pattern="[0-9]*" [(ngModel)]="myValue" pInputText class="medium-field" ...

Changing the color of a Navlink when focused

Can anyone help me modify the background color of a dropdown nav-link in Bootstrap? I am currently using the latest version and want to change it from blue to red when focused or clicked. I have included my navbar code below along with additional CSS, but ...

An inexplicable right margin

I am facing an issue with centering a table (a tracklist) under the album cover and title. There seems to be an unexpected margin on the right side that I can't seem to figure out. Any help in identifying the cause of this issue would be greatly appre ...

The functionality of responsive images is not functioning as intended within the Bootstrap framework

I'm currently working on troubleshooting a code issue. I am trying to implement a responsive image using Bootstrap, but it seems to not be functioning correctly. How can I go about resolving this problem? <header class="masthead text-center text-w ...

Can you show me the procedure for retrieving a particular element with selenium? (Page Source provided)

Disclaimer: I must admit that my knowledge of HTML and CSS is minimal, so please bear with me! Hello everyone, I am attempting to utilize selenium[Java] to browse a website and retrieve a file. While I managed to successfully get past the login page, I fi ...

Eliminate jQuery's delayed blinking effect with the use of an event

Utilizing the mouseenter and mouseleave events, I have implemented a functionality to add a button (not actually a button) to an <li>. However, there seems to be a problem with my code. The button appears and disappears on mouseleave and mouseenter, ...

Tailwind.css - a "sticky" element is positioned outside of the parent "wrapper" element

Seeking your kind assistance. I am facing an issue where a fixed element is being displayed outside the parent container on large screens, as it is treated as "fixed" from the viewport rather than relative to its parent element. Any suggestions on how to ...

Customizing HTML list headers using an external JavaScript function

Hi everyone, I've been working on a login page and I want to enhance the user experience by displaying the logged-in user's username at the top of the screen, which can then trigger a dropdown list upon clicking. To achieve this, I've writt ...

The dynamically inserted nested division within a bootstrap grid does not occupy the entire width of the parent division

I am working with a parent div where I am dynamically adding smaller divs with content to achieve a specific layout. Here's how the structure looks: https://i.sstatic.net/tN1s1.png The code for the parent div is shown below: <div class="row" sty ...